-
March 24th, 2019, 02:06 #1
Splitting stubborn data that doesn't want to split
So i'm currently trying to obtain data contained within combattracker.list.id-XXXXX.
when I print my variable this is what i get
combattracker-list.PNG
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.
Code: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
FG License: Unity Ultimate License
Timezone: -5 EST/EDT
-
March 24th, 2019, 03:23 #2
- Join Date
- May 2007
- Posts
- 84
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.)
-
March 24th, 2019, 03:40 #3
I was thinking pairs might work, but given my limited knowledge I assumed I was incorrect.
FG License: Unity Ultimate License
Timezone: -5 EST/EDT
-
March 24th, 2019, 03:46 #4
- Join Date
- May 2007
- Posts
- 84
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.)
-
March 24th, 2019, 03:49 #5
Omg that makes so much sense to pairs and impairs then any other explanation I've read. Lol
FG License: Unity Ultimate License
Timezone: -5 EST/EDT
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks