Mittell Buurman Posted August 11, 2013 Share Posted August 11, 2013 So here's what I have: A table(client & server) class = { { police={ guard = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, PER=1}, supervisor = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, PER=1} }, Prisoner={ fresh = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, SLT=1}, hardened = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, SLT=1} } } } A clientside for loop in a seperate file (for testing purposes i only output strings) for pIndex, classes in ipairs(class) do --Loop the classes outputDebugString(tostring(pIndex).." "..tostring(classes)) for index, classPackage in ipairs(classes['police']) do outputChatBox(tostring(index).." "..tostring(classPackage)) end end And this error in merely EVERY attempt As you can see I'm trying to retreive a table value in the 2nd for loop, But even if I remove the ['police'] part out of the table, I get no error, but also no string. Why isn't this working? I've been editing this for nearly 2 hours! Link to comment
Vector Posted August 11, 2013 Share Posted August 11, 2013 the table is not called "classes", is "class" for pIndex, classes in ipairs(class) do --Loop the classes outputDebugString(tostring(pIndex).." "..tostring(classes)) for index, classPackage in ipairs(classes) do outputChatBox(tostring(index).." "..tostring(classPackage)) end end Link to comment
Mittell Buurman Posted August 11, 2013 Author Share Posted August 11, 2013 the table is not called "classes", is "class" The first table is already called, the value of the classes is a table, now I want to get THAT table(which in that case defined in classes, so in my eyes it must return the table value), but instead of returning the table, it returns nil. Link to comment
InVision Posted August 11, 2013 Share Posted August 11, 2013 for pIndex, class in ipairs(class) do --Loop the classes outputDebugString(tostring(pIndex).." "..tostring(class)) for index, classPackage in ipairs(class['police']) do outputChatBox(tostring(index).." "..tostring(classPackage)) end end for pIndex, class in ipairs(class) do --Loop the classes outputDebugString(tostring(pIndex).." "..tostring(class)) for index, classPackage in ipairs(class['Prisoners']) do outputChatBox(tostring(index).." "..tostring(classPackage)) end end Link to comment
Mittell Buurman Posted August 11, 2013 Author Share Posted August 11, 2013 for pIndex, class in ipairs(class) do --Loop the classes outputDebugString(tostring(pIndex).." "..tostring(class)) for index, classPackage in ipairs(class['police']) do outputChatBox(tostring(index).." "..tostring(classPackage)) end end for pIndex, class in ipairs(class) do --Loop the classes outputDebugString(tostring(pIndex).." "..tostring(class)) for index, classPackage in ipairs(class['Prisoners']) do outputChatBox(tostring(index).." "..tostring(classPackage)) end end Link to comment
Castillo Posted August 11, 2013 Share Posted August 11, 2013 WIth your first script, I got no errors. class = { { police={ guard = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, PER=1}, supervisor = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, PER=1} }, Prisoner={ fresh = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, SLT=1}, hardened = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, SLT=1} } } } for pIndex, classes in ipairs(class) do --Loop the classes outputDebugString(tostring(pIndex).." "..tostring(classes)) for index, classPackage in pairs(classes['police']) do outputChatBox(tostring(index).." "..tostring(classPackage)) end end Link to comment
Mittell Buurman Posted August 11, 2013 Author Share Posted August 11, 2013 WIth your first script, I got no errors. class = { { police={ guard = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, PER=1}, supervisor = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, PER=1} }, Prisoner={ fresh = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, SLT=1}, hardened = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, SLT=1} } } } for pIndex, classes in ipairs(class) do --Loop the classes outputDebugString(tostring(pIndex).." "..tostring(classes)) for index, classPackage in pairs(classes['police']) do outputChatBox(tostring(index).." "..tostring(classPackage)) end end I've checked it, and now I get good results....I still don't get it. Link to comment
Castillo Posted August 11, 2013 Share Posted August 11, 2013 You can't use "ipairs" for that kind of tables, you must use "pairs". Link to comment
Mittell Buurman Posted August 11, 2013 Author Share Posted August 11, 2013 You can't use "ipairs" for that kind of tables, you must use "pairs". Ahh I see now, I tested again with ipairs and I had no error, but no results either. I'm so used of using ipairs, I never used pairs before. Thank you Link to comment
Mittell Buurman Posted August 12, 2013 Author Share Posted August 12, 2013 Since I recently made this topic, Let bring up the same issue, as I have no idea why this isn't working. the table is the same, now my code local str, def, int, sta, han, inv, wep, res, slt, per = nil wdwCreateCharacter=guiCreateWindow(sx*0.4, sy*0.4, sx*0.2, sy*0.2, "Pick a name", false) for pIndex, classes in ipairs(class) do --Loop the classes outputChatBox(tostring(classes)) for index, classPackage in pairs(classes['police']) do if (source==btnGuard) then for i, skills in pairs(classPackage['guard']) do str, def, int, sta, han, inv, wep, res, per = unpack(skills) end elseif (source==btnSergeant) then for i, skills in pairs(classPackage['sergeant']) do str, def, int, sta, han, inv, wep, res, per = unpack(skills) end end end end for pIndex, classes in ipairs(class) do --Loop the classes for index, classPackage in pairs(classes['prisoner']) do if (source==btnFresh) then str, def, int, sta, han, inv, wep, res, per = unpack(classPackage['fresh']) elseif (source==btnHardened) then str, def, int, sta, han, inv, wep, res, per = unpack(classPackage['hardened']) end end end The debugscript This is the line we're talking about in the debug. for i, skills in pairs(classPackage['guard']) do Now I tried solving it with pairs & ipairs (before I spent another 2 hours on the same issue), but that's not the issue. What do I miss here? Note, It starts in the guard area, I havent edited the bottom prisoners for chunk Link to comment
Castillo Posted August 12, 2013 Share Posted August 12, 2013 local str, def, int, sta, han, inv, wep, res, slt, per = nil wdwCreateCharacter=guiCreateWindow(sx*0.4, sy*0.4, sx*0.2, sy*0.2, "Pick a name", false) for pIndex, classes in ipairs(class) do --Loop the classes outputChatBox(tostring(classes)) if (source==btnGuard) then local skills = classes["police"]['guard'] outputChatBox ( skills.STR ) elseif (source==btnSergeant) then local skills = classes["police"]['sergeant'] outputChatBox ( skills.STR ) end end Link to comment
Mittell Buurman Posted August 12, 2013 Author Share Posted August 12, 2013 local str, def, int, sta, han, inv, wep, res, slt, per = nil wdwCreateCharacter=guiCreateWindow(sx*0.4, sy*0.4, sx*0.2, sy*0.2, "Pick a name", false) for pIndex, classes in ipairs(class) do --Loop the classes outputChatBox(tostring(classes)) if (source==btnGuard) then local skills = classes["police"]['guard'] outputChatBox ( skills.STR ) elseif (source==btnSergeant) then local skills = classes["police"]['sergeant'] outputChatBox ( skills.STR ) end end Great, thank you! Link to comment
Castillo Posted August 12, 2013 Share Posted August 12, 2013 You can't use "unpack" with that table. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now