Log In  

stars={}
for s=1,10do
add(stars,{x=128,y=128,spd=rnd(3)})
end
for i in all(stars)do
i.x-=i.spd
pset(i.x,i.y,7)
end

hey! super quick and basic question, feel like ive definitely done this before but i am just not thinking hard enough rn but why isn't this working? no errors are being thrown so i feel like im definitely forgetting something super basic thats making it all break but i am still a beginner and can't seem to figure out what. ty for any help!

P#121581 2022-11-29 21:16

So there's nothing wrong with the array itself it's your x, y and spd values that are causing the problem.

Even though Lua indexes starting at 1 the top-left corner of the screen is (0, 0). That means (128, 128) is actually just off the bottom right-hand side of the screen. And since your spd value is positive when you update it, it just moves further off the screen.

Edit: Ugh, sorry didn't notice you're subtracting the spd. But it's still not showing because the pixel is still off the bottom of the screen even though it's not longer off the right.

By the way, in case you're not aware, you can put code inside triple backticks to display it a bit nicer on the BBS.

```
function some_code()
return 0
end
```

Gives this:

function some_code()
   return 0
end
P#121583 2022-11-29 21:27 ( Edited 2022-11-29 21:33)

oh lol. i did that initially but it didnt change anything in the editor so i didnt think it did anything. thank you, this works! doesnt update position, just draws it statically at the new x-spd position but thats something else i can work out. thanks!
cash <3

P#121585 2022-11-29 21:44

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 14:02:02 | 0.006s | Q:13