i have no idea if this is the right place to put this here it is anyways. i'm making something along the lines of space invaders. i have a system for shooting but i just cannot get the projectile to work the way i want it to. when you hit the button the sprite just shoots up the screen. here's an excerpt of what i have:
t=0
px=96 --player x
py=24 -- player y
lx=px-7 --projectile x --makes sure it starts in line with a part of the player's sprite
ly=lx+4 --projectile y --offset to account for the projectile's sprite's placement
function TIC()
if btnp(4,30,6) then
ly=py-7
lx=px+4
while ly>0 do
ly=ly-1
spr(288,lx,ly,0)
end
end
t=t+1
end
(i know this could easily look much nicer but i am restricted in character count so using something like p.x and p.y would use too many characters) i've tried to nest an if loop into the while loop like so:
while ly>0 do
if t%8==0 then
ly=ly-1
spr(288,lx,ly,0)
t=t+1
end
end
but when i try this, on triggering it just bricks the entire console, which requires me to open task manager and close it from there. i've tried putting the if in different spots and moving/removing the "t=t+1" line but nothing works. one thing that maybe meant something is that trying "if math.random(8)==1" did not brick the console but did not slow down the movement either. because of that i believe i've tracked the problem back to the while loop; it just goes too fast. it runs so fast that the math.random doesn't affect it because it can choose new values so quickly that it will just get the required value incredibly quickly anyways. nesting it in another if loop doesn't work either because that would dictate if the while loop starts at all. if anyone has any idea what could be happening here or anything i could change about this let me know.