It seems like my code is overwriting itself, so even though I should end up with 12 items, I end up with 6. What am I doing wrong?
Here’s the data (player_assets.lua):
[lua]
local PlayerAssets = {
default = “default”,
layers = {“body”, “head”, “legs”, “sword”, “shoulder”, “glove”},
modes = {
default = {
glove = “art.player.1_Glove”,
shoulder = “art.player.2_Shoulder”,
sword = “art.player.3_Sword”,
legs = “art.player.4_Legs”,
head = “art.player.5_Head”,
body = “art.player.6_Body”,
},
pain = {
head = “art.player.5_Head_Pain”,
},
fire = {
glove = “art.player.1_Fire_Glove”,
shoulder = “art.player.2_Fire_Shoulder”,
legs = “art.player.5_Fire_Legs”,
head = “art.player.6_Fire_Head”,
body = “art.player.7_Fire_Torso”,
},
},
}
return PlayerAssets
[/lua]
And here’s where I call it (player.lua):
[lua]
function bhvr.general.init(self)
local loqsprite = require (“loq_sprite”)
self.assets = require(“player_assets”)
local img = nil;
self.spriteFactory = {}
local mode = self.assets.modes
for mode,assets in pairs(self.assets.modes) do
for i=1, #self.assets.layers do
local part = self.assets.layers[i]
if (assets[part]) then
img = bhvr.general.loadPlayerImg(assets[part])
self.spriteFactory[i] = loqsprite.newFactory(img)
self.spriteFactory[i].startup = true
–print("img: ", img)
print(#self.spriteFactory)
end
–print("i: ", i)
end
end
end
function bhvr.general.loadPlayerImg(file)
local img = file
return img
end
[/lua]
When I print “#self.spriteFactory”, I get…
[lua]
2013-03-11 17:35:11.183 Corona Simulator[9554:f03] 1
2013-03-11 17:35:11.185 Corona Simulator[9554:f03] 2
2013-03-11 17:35:11.187 Corona Simulator[9554:f03] 3
2013-03-11 17:35:11.188 Corona Simulator[9554:f03] 3
2013-03-11 17:35:11.189 Corona Simulator[9554:f03] 3
2013-03-11 17:35:11.191 Corona Simulator[9554:f03] 3
2013-03-11 17:35:11.193 Corona Simulator[9554:f03] 3
2013-03-11 17:35:11.195 Corona Simulator[9554:f03] 3
2013-03-11 17:35:11.196 Corona Simulator[9554:f03] 6
2013-03-11 17:35:11.198 Corona Simulator[9554:f03] 6
2013-03-11 17:35:11.199 Corona Simulator[9554:f03] 6
2013-03-11 17:35:11.201 Corona Simulator[9554:f03] 6
[/lua]
If I uncomment the prints above, “i” will count up to 12, and “img” will correctly show all of the data. What did I miss? [import]uid: 191140 topic_id: 37526 reply_id: 67526[/import]