PDA

View Full Version : Splitting stubborn data that doesn't want to split



MyGivinOpinion
March 24th, 2019, 02:06
So i'm currently trying to obtain data contained within combattracker.list.id-XXXXX.
when I print my variable this is what i get

26820

now what I haven't shown what i've attempted to do with it. I'm trying to split the values up and StringManager.split() doesn't do anything. the for loop i use earlier works but the second for loop which is identical in structure won't ever process it seems.



function onCall()
local tokenCT = CombatManager.getCombatantNodes(); --{ s'id-*****' = databasenode = {combattracker.list.id-***** }, s'id-*****' = databasenode = {combattracker.list.id-***** }}
Debug.console(tokenCT);
for i, v in ipairs(tokenCT) do
Debug.console(v);
end

end

Can someone help me? no output is being displayed for the value of tokenCT during the for loop. trying to figure out why/how to fix it..

gamerhawaii
March 24th, 2019, 03:23
I cannot explain why, but change "ipairs" to "pairs". Using "ipairs" seems to never go into the loop. Using "pairs" does. (Maybe one of the nodes is nil? Cannot really explain it. But using your exact code, pairs works and ipairs does not.)

MyGivinOpinion
March 24th, 2019, 03:40
I was thinking pairs might work, but given my limited knowledge I assumed I was incorrect.

gamerhawaii
March 24th, 2019, 03:46
I just looked it up (and this might be right or wrong), it looks like ipairs will look in the table assuming the items are indexed starting at 1. So tokenCT[1], tokenCT[2], etc. However, tokenCT is actually indexed with the node number (tokenCT["id-00002"], tokenCT["id-00001"], etc.) Therefore, you need to use pairs which does not make assumptions about the indexing. (Again, that is how I interpret it, but I could be wrong.)

MyGivinOpinion
March 24th, 2019, 03:49
Omg that makes so much sense to pairs and impairs then any other explanation I've read. Lol