Log In  

Can someone explain how arrays work?

It's very much bugging me out :(

P#10849 2015-05-21 23:54 ( Edited 2015-05-22 21:38)

What specifically are you having trouble with? This would probably be a good start: http://www.lua.org/pil/11.1.html

P#10865 2015-05-22 13:27 ( Edited 2015-05-22 17:27)

I'm trying to figure out how arrays work, PICO-8 specific arrays

basically, I want to try and make a starfield for example

P#10866 2015-05-22 15:16 ( Edited 2015-05-22 19:32)

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

P#10867 2015-05-22 16:41 ( Edited 2015-05-22 20:41)

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

P#10868 2015-05-22 17:07 ( Edited 2015-05-22 21:07)

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}
  }
}
P#10871 2015-05-22 17:12 ( Edited 2015-05-22 21:17)

I see.

another question I would have is
how you would draw arrays, like sprites?

P#10873 2015-05-22 17:25 ( Edited 2015-05-22 21:25)

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.

P#10874 2015-05-22 17:38 ( Edited 2015-05-22 21:39)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-16 21:31:55 | 0.007s | Q:19