Dict issue, help please!
Mar 05 2015 | 11:18 pm
I have a dictionary called session_tokens like this:
{ "current_objects" : { "first" : { "type" : "nlayer" } , "second" : { "type" : "nlayer" } , "third" : { "type" : "nlayer" } } }
Every element inside current_objects represents a token inside a system, so this way i can handle them for other purposes, the thing that matters is that first, second and third are the name of the tokens.
I created a function EXECUTEORDER66 (yes, i’m a SW fan) that destroys all tokens at the same time and delete them from dictionary session_tokens, so after EXECUTEORDER66current_objects should be empty.
EXECUTEORDER66 is this function:
function EXECUTEORDER66 { targets = element_iter("current_objects"); if(targets) { for(i=0;i
targets is and array with current tokens, so:targets[0] = firsttargets[1] = secondtargets[2] = third
it's gotten from the element_iter function, which is this:
function element_iter(id) { dict = new Dict("session_tokens"); if(dict.contains(id)) { current_elements = dict.get(id); elements = current_elements.getkeys(); if(elements instanceof Array) { return elements; } else if ((typeof elements) == "string") { elements = [elements]; //This transforms the string element in a single element array return elements; else { return null; } } else { return null; } }
If there’s no token current_objects should be empty and targets will be null because element_iter returns null in that case. Everything up to this point is working fine.
Inside the for cycle i’m posting the current target to Max Window and then using whisper function. This functions deletes a token from the system and removes it from the dictionary. Whisper alone is working OK for a single call, but when i use EXECUTEORDER66 the i inside the cycle seems to change even then it hasn’t complete a single loop:
The first post(targets[i]) results in “first” which is fine, then the “first” token is deleted correctly but post(targets[i]) after whisper function returns “third” and not “first” again like i’m expecting.
Then the cycle stops and never perform a loop again, like i think it should do because the array has 3 elements.
I think my problem is related with dictionaries because im rookie with them.
Thank you in advance!