Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arrays and Tables
#1
I am familiar with arrays and gradually getting my head around tables... My question may be lame but I need to know... How does one determine whether to use an array or a table?

J
Logic is the beginning of wisdom.
Reply
#2
(11-24-2024, 09:17 PM)johnno56 Wrote: I am familiar with arrays and gradually getting my head around tables... My question may be lame but I need to know... How does one determine whether to use an array or a table?

J

HI Johnno,

I have never felt the need to distinguish between the two, but perhaps the explanation of Tables in the document for migrating from N6 will help:


.pdf   ReadMe.pdf (Size: 124.85 KB / Downloads: 8)

All the best - Kevin.
Reply
#3
Cool. Thank you for the PDF. Hopefully it will make things a lot clearer...

J
Logic is the beginning of wisdom.
Reply
#4
It doesn't really matter what you use Smile I think tables (arrays are just a special case) make things look clearer. Let's say you want to have an array with 100 enemies, where each enemy has an image, a position (x, y) and speed (x, y):

Code:
anImage = loadimage("dummy.png")

' using numeric indexes.
enemies = fill([0, 0, 0, 0, 0], 100)
' set image, position and speed of enemy 53.
enemies[53][0] = anImage
enemies[53][1] = 91
enemies[53][2] = 132
enemies[53][3] = 1
enemies[53][4] = -1

' using string keys.
enemies = fill([img: 0, x: 0, y: 0, dx: 0, dy: 0], 100)
enemies[53].img = anImage
enemies[53].x = 91
enemies[53].y = 132
enemies[53].dx = 1
enemies[53].dy = -1
Reply
#5
Thanks Marcus. Much appreciated.
Logic is the beginning of wisdom.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)