Can someone explain how arrays work?
It's very much bugging me out :(
What specifically are you having trouble with? This would probably be a good start: http://www.lua.org/pil/11.1.html
I'm trying to figure out how arrays work, PICO-8 specific arrays
basically, I want to try and make a starfield for example
Oh, so you don't mean "array" as a data structure, but some other definition of "array"? I'm not sure what you are asking :D
I'm trying to make a game, with multiple actors.
However,
I have no idea how it's done.
I know that arrays are used to make players and actors, but I wish someone would teach me about how it actually works. I'm very confused myself
You can use tables as arrays:
local a = {} a[1]="hello" a[2]="world" for i=1,2,1 do print(a[i]) end |
They're 1 based and don't have a length, as far as I know at least...
You can also use tables as JSON styled objects, just imagine = instead of :
{ x=0, y=0, xv=0, yv=0, guns={ {t=0,bullets=30}, {t=1,bullets=2} } } |
I see.
another question I would have is
how you would draw arrays, like sprites?
Imagine an array spr[] full of tables, like {x=0,y=0,spr=0}
for i=1,sprLen,1 do local s = spr[i] spr(s.spr,s.x,s.y) end |
where spr is the sprite number.
[Please log in to post a comment]