Posted 16 June 2015 - 04:22 PM
This is something strange that I have never dealt with. I have a multidimensional array that all have strings for their indexes/names. However, when I try to go through with for i,v in pairs(), for whatever reason the loop doesn't go through each item consecutively, instead it jumps around to other values. I need to get the number of the index in order to do stuff with the rest of my program.
Because I can't find anything online telling me if there is a way to get the index number of a table by having the index value, I had to do a work around. Instead, I created a basic number at the beginning and every time the loop went through I increased the number, that way I knew what index I was in… but like I said, that doesn't work because I just recently discovered that i,v in pairs doesn't seem to go through the table in order…. which messes EVERYTHING up…. so how do I fix this?
I really hope what I said makes sense XD it's early in the morning so sorry If you didn't understand anything I was talking about
Edit: For whatever reason the spacing in the code is weird… fixing it right now
Because I can't find anything online telling me if there is a way to get the index number of a table by having the index value, I had to do a work around. Instead, I created a basic number at the beginning and every time the loop went through I increased the number, that way I knew what index I was in… but like I said, that doesn't work because I just recently discovered that i,v in pairs doesn't seem to go through the table in order…. which messes EVERYTHING up…. so how do I fix this?
main = {
cobble = {"cobblestone"}
stone = {"stone"}
wood = {"oaklogs"}
}
for i,v in pairs(inventory) do --A different table that I use for other stuff
tempNumber = 1
for n,p in pairs(main) do
if v== l[1] then
print(tempNumber.. " : "..l[1])
end
tempNumber = tempNumber + 1
end
end
I really hope what I said makes sense XD it's early in the morning so sorry If you didn't understand anything I was talking about
Edit: For whatever reason the spacing in the code is weird… fixing it right now
Edited on 16 June 2015 - 02:32 PM