Unknown bug

Hi i am a noob at codea and having trying to build a game.
When i try the following code it says that there is an error on line 77 and that ta is a nil value.
Could someone pls tell me how to fix this??

function setup()
    displayMode(FULLSCREEN)
    x1=0
    y1=0
    joystick1setup()
    joystick2setup()
end

function draw()
   background(45, 25, 43, 255)
   stroke(255, 0, 0, 255)
   strokeWidth(5)
   line(x1,y1,lx,ly)
   lineCapMode(ROUND)
   noStroke()
   fill(223, 209, 166, 255)
   ellipse(cx, cy, 90)
   joystick1draw()
   joystick2draw()
end

function touched (t)
    --left joystick
    if t.state==BEGAN and t.x<WIDTH/2 then    -- starting center point
        x=t.x
        y=t.y
        tx=x
        ty=y
    elseif t.state==MOVING then
        tx=t.x
        ty=t.y
    elseif  t.state==ENDED then    -- done moving
        x,y=0,0
    end
    --right joystick
    if t.state==BEGAN and t.x>WIDTH/2 then    -- starting center point
        a=t.x
        b=t.y
        ta=a
        tb=b
    elseif t.state==MOVING then
        ta=t.x
        tb=t.y
    elseif  t.state==ENDED then    -- done moving
        a,b=cx,cy
    end
end
--joystick left for planet
function joystick1setup()
    cx=WIDTH/2
    cy=HEIGHT/2
    x,y=0,0
end

function joystick1draw()
    if x + y>0 then
        cx=cx+(tx-x)/10
        cy=cy+(ty-y)/10
        fill(255, 255, 255, 255)
        ellipse(x,y,8)    -- draw circle center
        noFill()
        stroke(255, 255, 255, 255)
        strokeWidth(4)
        ellipse(x,y,170)    -- draw outer circle
    end
end
--joystick right for laser
function joystick2setup()
    lx=cx
    ly=cy
    a,b=cx,cy
end

function joystick2draw()
    if a + b>0 then
        lx=lx+(ta-a)/10
        ly=ly+(tb-b)/10
        fill(255, 255, 255, 255)
        ellipse(a,b,8)    -- draw circle center
        noFill()
        stroke(255, 255, 255, 255)
        strokeWidth(4)
        ellipse(a,b,170)    -- draw outer circle
    end
end

you need to set ta, tb etc to 0 (or something else) in setup, otherwise they will be nil when the draw function tries to use them. At the moment, you only give them a value when a touch happens.

PS use this
~~~
code
~~~
to make your code format properly, I fixed yours above.

Thx that really helps

@Klupa56 The mistake you made was made by all of us. I still make that mistake now. I’ve made it so many times that it doesn’t even bother me anymore because I know what it means. An important part of writing code is to make mistakes and learn from them. The more mistakes you make, the easier it is to write better code later on. A lot of times when I’m bored, I’ll write code and purposely make mistakes just to see what kind of a message will show.