Checkers help

So I am (was) making for the game competition. I have hit a roadblock. I am not good enough with lua to find my error so I need help, I realize this also probably cancels this project for the competition, for everyone sees what it is, but oh we’ll. The issue is with currentTouch.state. I am trying to get a specific checker to move when I drag it and then when I click another, have it not instantly zoom to the old currentTouch.

  r1x=95
  r1y=95
  r2x=175
  r2y=95
  r3x=255
  r3y=95
  r4x=335
  r4y=95

function draw()
    touch()
    background(0, 0, 0, 255)
    fill(255, 255, 255, 255)
    --the game board
    rect(55,55,80,80)
    rect(215,55,80,80)
    rect(375,55,80,80)
    rect(535,55,80,80)
    rect(135,135,80,80)
    rect(295,135,80,80)
    rect(455,135,80,80)
    rect(615,135,80,80)
    rect(55,215,80,80)
    rect(215,215,80,80)
    rect(375,215,80,80)
    rect(535,215,80,80)
    rect(135,295,80,80)
    rect(295,295,80,80)
    rect(455,295,80,80)
    rect(615,295,80,80)
    rect(55,375,80,80)
    rect(215,375,80,80)
    rect(375,375,80,80)
    rect(535,375,80,80)
    rect(135,455,80,80)
    rect(295,455,80,80)
    rect(455,455,80,80)
    rect(615,455,80,80)
    rect(55,535,80,80)
    rect(215,535,80,80)
    rect(375,535,80,80)
    rect(535,535,80,80)
    rect(135,615,80,80)
    rect(295,615,80,80)
    rect(455,615,80,80)
    rect(615,615,80,80)
    -- the checker pieces
        touch()
    fill(255, 0, 0, 255)
    ellipse(r1x,r1y,50,50)
    end
    
   
function touch()
    x=CurrentTouch.x
    y=CurrentTouch.y
    if CurrentTouch.state==BEGAN then
        if x>r1x-25 and x<r1x+25 and y>r1y-25 and y<r1y+25 then
            r1x=CurrentTouch.x
            r1y=CurrentTouch.y
            end
        
    if CurrentTouch.state==ENDED then
        x=nil
        y=nil
        end
    end
end

Thanks for the help! (sorry if the code comes up without enters, that seems to happen a lot with it.)

CurrentTouch.state==BEGAN or CurrentTouch.state==MOVING

Does that help?

That did the trick. Thanks a ton.

Dang it now it’s pestering me about end of function needed near end. I have so many ends in, what’s going on?

Never mind I got it to play, but I added another checker to the function touch() and function draw() sections and it is having the same problem as the first.

Too many "end"s in a row means you should consider breaking part of what you’re doing out into its own function.

Alternatively, try “end – touch()” or such to keep track of which end pairs with what.

Well it’s not that. I fixed the ends stuff. It’s just the second checker is having the same issue as the first, it won’t be dragged but will move when touched,


  r1x=95
  r1y=95
  r2x=255
  r2y=95
  r3x=255
  r3y=95
  r4x=335
  r4y=95

function draw()
    touch()
    background(0, 0, 0, 255)
    fill(255, 255, 255, 255)
    --the game board
    rect(55,55,80,80)
    rect(215,55,80,80)
    rect(375,55,80,80)
    rect(535,55,80,80)
    rect(135,135,80,80)
    rect(295,135,80,80)
    rect(455,135,80,80)
    rect(615,135,80,80)
    rect(55,215,80,80)
    rect(215,215,80,80)
    rect(375,215,80,80)
    rect(535,215,80,80)
    rect(135,295,80,80)
    rect(295,295,80,80)
    rect(455,295,80,80)
    rect(615,295,80,80)
    rect(55,375,80,80)
    rect(215,375,80,80)
    rect(375,375,80,80)
    rect(535,375,80,80)
    rect(135,455,80,80)
    rect(295,455,80,80)
    rect(455,455,80,80)
    rect(615,455,80,80)
    rect(55,535,80,80)
    rect(215,535,80,80)
    rect(375,535,80,80)
    rect(535,535,80,80)
    rect(135,615,80,80)
    rect(295,615,80,80)
    rect(455,615,80,80)
    rect(615,615,80,80)
    -- the checker pieces
        touch()
    fill(255, 0, 0, 255)
    ellipse(r1x,r1y,50,50)
    ellipse(r2x,r2y,50,50)
    end
    
   
function touch()
    x=CurrentTouch.x
    y=CurrentTouch.y
    if CurrentTouch.state==BEGAN or CurrentTouch.state==MOVING then
        if x>r1x-25 and x<r1x+25 and y>r1y-25 and y<r1y+25 then
            r1x=CurrentTouch.x
            r1y=CurrentTouch.y
            end
        elseif x>r2x-25 and x<r2x+25 and y>r2y-25 and y<r2y+25 then
            r2x=CurrentTouch.x
            r2y=CurrentTouch.y
            end
        end
        
    if CurrentTouch.state==ENDED then
        x=nil
        y=nil
        end 
function touch()
    x=CurrentTouch.x
    y=CurrentTouch.y
    if CurrentTouch.state==BEGAN or CurrentTouch.state==MOVING then
        if x>r1x-25 and x<r1x+25 and y>r1y-25 and y<r1y+25 then
            r1x=CurrentTouch.x
            r1y=CurrentTouch.y
            --end removed
        elseif x>r2x-25 and x<r2x+25 and y>r2y-25 and y<r2y+25 then
            r2x=CurrentTouch.x
            r2y=CurrentTouch.y
            --end removed
        end --checkers
    end -- touch began --added
        
    if CurrentTouch.state==ENDED then
        x=nil
        y=nil
        end --ended touch
        
end --function --added