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