lua - attempt to call a nil value -
for = 1, groupa:getnumchildren() local sprite = groupa:getchildat(i) if cute.anim[1]:collideswith(sprite) youloose() end end local function youloose() local font3 = ttfont.new("billo.ttf", 20, " 1234567890abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz,?") local text7 = textfield.new(font2, "gameover") text7:setposition(200, 100) stage:addchild(text7) gamelost = bitmap.new(texture.new("gameover.jpg")) background : removefromparent() groupa : removefromparent() stage: addchild(gamelost) alert() end
it gives error says 'attempt call global youloose (a nil value)
, doing wrong?
note collideswith
not same collideswith
; if error posted correct, posted code different using. method called collideswith
(it appears if 1 sprite1
), used collideswith
. alternatively, if code posted used, error attempt call collideswith(a nil value)
, cute.anim[1]
not sprite1
object, not nil either otherwise error different.
once have fixed this, you'll notice youloose
defined after for
loop, when call youloose()
not yet defined. you're going have move local function youloose()
function before loop. because loop not in function, @ module level, gets executed before following code, functions (local or global) used in loop must defined before loop.
note "loose" not mean same "lose". check grammar-monster see difference. everywhere have word "loose" should change "lose".
Comments
Post a Comment