Hey guys. I’ve loaded a json file and tossed it into a table. I’ve been successful in using the values as i pleased. But I’ve been hardcoding the values in the table.
local myBadgeArray = {
myTable[2].badge,
myTable[3].badge,
myTable[4].badge,
myTable[5].badge,
myTable[6].badge
}
However, Im trying to write some lua to just read the json values itself since i dont know how long the json is going to get. I ended up with something like this…
local myBadgeArray = { }
tValS = "myTable["
tValE = "]."
tValB = "badge"
for k, v in pairs(myTable) do
if k==1 then
table.insert(featureTable,k,tValS..k..tValE..tValB..",")
else
table.insert(myBadgeArray,k,tValS..k..tValE..tValB..",")
print(myBadgeArray[k])
--print(#myBadgeArray)
end
end
So that prints out exactly like the hardcoded table (myTable[2].badge and so on…) Which on the json file points to “g_bug_10off.png”, etc.
then I have another loop to take these table values and format them as i like…
for i,v in pairs(myBadgeArray) do
myBadges[i] = display.newImage("images/"..v,0,120)
myBadges[i]:translate(100,(i-1) \* 102)
myBadges[i]:scale(.75,.75)
myBadges[i]:setReferencePoint(display.CenterReferencePoint);
myBadges[i]:addEventListener("tap", ImageClicked)
coupGroup:insert(myBadges[i])
end
Okay… Here is where im getting confused. When I run this with the hardcoded table, my lua finds the images no problemo. But when i run the table insert script, instead of looking for “g_bug_10off.png”, its looking for “myTable[2].badge” in my images folder!?
Anyone know what im doing wrong here? I have a feeling im over thinking this but was just wondering if i missed something
Any help would be awesome! Thanks guys!
-Kel [import]uid: 88004 topic_id: 27463 reply_id: 327463[/import]