Taking turns in two player game

I am very new to Codea and my programming skills are very limited, but am trying to show 10yo what can be achieved with very simple programming.
I am creating a game where player A touches part of screen to increase his score by given number of points, then player B claims points from another part of screen, then players alternate until all points claimed.
I can switch from A to B, but cannot repeatedly alternate between the two players and can find few sample games with code that I can look at to see how it is done.
Any simple solutions?

@ihjones Without knowing more about what you want to do, here is a simple way to switch between 2 players when touching the screen. Each time you touch the screen, either function playerA() is called or playerB() is called. You can set table values or whatever code you want for each player.


displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT)

function setup()
    func=playerA
    player="player A"    -- current player
end

function draw()
    background(40, 40, 50)
    fill(255)
    text(player,300,600)    -- just showing current player on screen
end

function touched(t)
    if t.state==BEGAN then
        if func==playerA then
            func=playerB
        else
            func=playerA
        end
    end
    func()    -- perform function for player A or B
end

function playerA()    -- perform code for player A
    player="player A"
end

function playerB()    -- perform code for player B
    player="player B"
end

@ihjones I was looking thru my programs again to see what to delete and came across this one and thought it might help you. The purpose of this program is for each player to alternate picking a circle. Each circle has a value. The smaller the circle, the higher the value. As each circle is selected, it’s value is added to the players score, then the circle is removed from the screen. The circle may or may not reveal a smaller circle beneath it. The selection continues until all the circles are gone and the winner has the highest score. This is a simple program, so I hope this will help you. I add comments to help you understand it easier.


displayMode(FULLSCREEN)
font("Courier-Bold")

function setup()
    textMode(CORNER)
    player=1
    score={0,0}
    circTab={}    -- circle table  vec4(x,y,size,value)
    colTab={}     -- circle color table
    for z=1,150 do    -- create 150 circles with random x, y positions,  sizes and values
        size=math.random(20,100)    -- random size
        value=110-size    -- circle value
        circTab[z]=vec4(math.random(50,WIDTH-50),math.random(100,HEIGHT-200),size,value)        
        colTab[z]=color(math.random(255),math.random(255),math.random(255))
    end    
end

function draw()
    background(40, 40, 50)
    for z=1,#circTab do    -- draw circles using values from circle table
        fill(colTab[z])    -- circle color
        ellipse(circTab[z].x,circTab[z].y,circTab[z].z*2)  -- draw circles
    end 
    fill(255)
    str=string.format("Circles %3d   Player 1 = %4d       Player 2 = %4d",#circTab,score[1],score[2])
    text(str,57,1000)
    if player==1 then
        text("---------------",200,980)
    else
        text("---------------",425,980)
    end
end

function touched(t)
    if t.state==BEGAN then
        for z=#circTab,1,-1 do  -- check which circle is touched
            if (t.y-circTab[z].y)^2/circTab[z].z^2+(t.x-circTab[z].x)^2/circTab[z].z^2 <= 1 then
                score[player]=score[player]+circTab[z].a    -- add score to player
                table.remove(circTab,z)    -- remove circle from table
                table.remove(colTab,z)    -- remove color from table
                if player==1 then    -- switch player
                    player=2
                else
                    player=1
                end
                break
            end
        end
    end   
end