Hmm… I’ll keep that in mind and in my archives Danny. Thank you for providing the method. I think I need to read more Lua documentation. [import]uid: 154911 topic_id: 36282 reply_id: 144336[/import]
Are both of them [lua]levelData.objects[1][/lua] or is it supposed to be like [lua]levelData.objects[1][/lua] and [lua]levelData.objects[2][/lua]? [import]uid: 154911 topic_id: 36282 reply_id: 144192[/import]
I’m going to oversimply here but create your table like this:
levelData.objects = {}
levelData.objects[1] = {name = "heartNeckLace", src = "filepath", x = 200, y = 500}
levelData.objects[2] = {name = "playingCarBox", src = "filepath", x = 100, y = 80}
And so on… Then when you want to read them out call them like this:
print(levelData.objects[1].name)
good luck!
[import]uid: 70134 topic_id: 36282 reply_id: 144166[/import]
Good call! Yes, I edited my post, you’re supposed to use incremental numbering! [import]uid: 70134 topic_id: 36282 reply_id: 144193[/import]
Hmm I’m getting an error from the syntax. What may be the problem?
[lua]
levelData.objects = {}
levelData.objects =
{
levelData.objects[1] =
{
src = “images/levels/level1/necklace.png”,
x = 170,
y = 83,
},
levelData.objects[2] =
{
src = “images/levels/level1/cardbox.png”,
x = 311,
y = 55,
},
levelData.objects[3] =
{
src = “images/levels/level1/racket.png”,
x = 430,
y = 66,
},
levelData.objects[4] =
{
src = “images/levels/level1/statue.png”,
x = 350,
y = 66,
},
}
[/lua] [import]uid: 154911 topic_id: 36282 reply_id: 144196[/import]
Ah ok, I figured out my problem Thank you. I’m trying this now [import]uid: 154911 topic_id: 36282 reply_id: 144197[/import]
Was just about to step in but I’m guessing you’ll be fine now! [import]uid: 70134 topic_id: 36282 reply_id: 144198[/import]
Lua tables that are indexed by number will have their order guaranteed, but those that are done using a text key can be in any order. [import]uid: 199310 topic_id: 36282 reply_id: 144215[/import]
Thank you for the help. It worked perfectly for me. [import]uid: 154911 topic_id: 36282 reply_id: 144306[/import]
You can keep your key naming convention by using a function like this ( which iterates through them in order ) : http://lua-users.org/wiki/SortedIteration [import]uid: 84637 topic_id: 36282 reply_id: 144330[/import]
Hmm… I’ll keep that in mind and in my archives Danny. Thank you for providing the method. I think I need to read more Lua documentation. [import]uid: 154911 topic_id: 36282 reply_id: 144336[/import]
Are both of them [lua]levelData.objects[1][/lua] or is it supposed to be like [lua]levelData.objects[1][/lua] and [lua]levelData.objects[2][/lua]? [import]uid: 154911 topic_id: 36282 reply_id: 144192[/import]
I’m going to oversimply here but create your table like this:
levelData.objects = {}
levelData.objects[1] = {name = "heartNeckLace", src = "filepath", x = 200, y = 500}
levelData.objects[2] = {name = "playingCarBox", src = "filepath", x = 100, y = 80}
And so on… Then when you want to read them out call them like this:
print(levelData.objects[1].name)
good luck!
[import]uid: 70134 topic_id: 36282 reply_id: 144166[/import]
Good call! Yes, I edited my post, you’re supposed to use incremental numbering! [import]uid: 70134 topic_id: 36282 reply_id: 144193[/import]
Hmm I’m getting an error from the syntax. What may be the problem?
[lua]
levelData.objects = {}
levelData.objects =
{
levelData.objects[1] =
{
src = “images/levels/level1/necklace.png”,
x = 170,
y = 83,
},
levelData.objects[2] =
{
src = “images/levels/level1/cardbox.png”,
x = 311,
y = 55,
},
levelData.objects[3] =
{
src = “images/levels/level1/racket.png”,
x = 430,
y = 66,
},
levelData.objects[4] =
{
src = “images/levels/level1/statue.png”,
x = 350,
y = 66,
},
}
[/lua] [import]uid: 154911 topic_id: 36282 reply_id: 144196[/import]
Ah ok, I figured out my problem Thank you. I’m trying this now [import]uid: 154911 topic_id: 36282 reply_id: 144197[/import]
Was just about to step in but I’m guessing you’ll be fine now! [import]uid: 70134 topic_id: 36282 reply_id: 144198[/import]
Lua tables that are indexed by number will have their order guaranteed, but those that are done using a text key can be in any order. [import]uid: 199310 topic_id: 36282 reply_id: 144215[/import]
Thank you for the help. It worked perfectly for me. [import]uid: 154911 topic_id: 36282 reply_id: 144306[/import]
You can keep your key naming convention by using a function like this ( which iterates through them in order ) : http://lua-users.org/wiki/SortedIteration [import]uid: 84637 topic_id: 36282 reply_id: 144330[/import]