can someone tell me why I am getting nil when printing out the stars px and py values?
local stars={}
for i=0, 16 do add(stars,{x=rnd(128),y=rnd(128),px=x,py=y,c=7}) end --px and py are equal to x and y
drwmenu=function()
if btn(2) then menuind-=1 end
if btn(3) then menuind+=1 end
menuind=mid(0,4)
for v in all(stars) do
print(v.px) --prints nil
print(v.py) --prints nil
line(v.x,v.y,v.px,v.py,v.c)
--line(v.x,v.y-128,v.px,v.py,v.c)
--v.py=v.y
--v.y+=8
if v.y > 127 then v.y-=128 end
end
if (time()-last > 1) then
rectfill(0,112,127,120,1)
print("press start!",0,114,7)
if (time()-last > 2) then last=time() end
end
end
|
P#65802 2019-07-13 05:25
Because when you create your stars you're assigning them using x and y variables that don't exist. You'll need to create some local variables and use those to assign the values.
for i=0, 16 do
local x,y=rnd(128),rnd(128)
add(stars,{x=x,y=y,px=x,py=y,c=7})
end |
P#65803 2019-07-13 06:05
[Please log in to post a comment]



