Forcing code execution before moving on

I am trying to set a couple of _global variables with if-then statement, and just after this, use these _globals in the code.

However, the code moves on before the _globals are properly set.

How can I make the code wait (no timers, please) until the _globals are set?

if (_globals != undefined) {
// do yo thang
}

Thanks for the reply.

However, the globals change regularly and are always defined.
How could I wait for a _global to CHANGE its current value?

I could probably undefine them first, and then define them again, and thus use this code.
But since undefining a _global also takes time, the code could move on before it is undefined and use the old value.

Any ideas?

Difficult one, huh? What a screwed up problem - Im pretty sure AS is the only programminglanguage that lets the code continue without having set the variables first LOOOL

did you trace() them to check? shouldn’t happen…?

Yep, puh I dont think Ive ever done so much debugging before. Im very close to a nervous breakdown right now :crazy:


Process1:

  1. I put the _globals to “0” before entering a if-else loop.

  2. I redefine _globals in if-else loop.

  3. I use _globals new values immediately after the if-else loop is finished (and _globals are defined/redefined) in a function.

Result:

All _globals have value “0”.


Process 2:

  1. I put the _globals to “0” before entering a if-else loop. (same as before)

  2. I redefine _globals in if-else loop. (same as before)

  3. I need to press a button to call the function (same function as before - only difference is that I wait a while).

Result:

All _globals use correct values.

Conclusion:

_globals are not defined properly before code moves on.

Remedy:

Well, with sharedObjects you can use the function “flush” to force the value into the sharedObject immediately.
If there is a similar function for _globals that could solve the problem.

*Originally posted by Danneman *
How could I wait for a _global to CHANGE its current value?
just put the global vars into another variable and check to see if it’s the same the next time it loops around:

oldglob = _global; //put this right before you have the global variable change
if (_global != oldglob) {
// do yo thang
} else {
// don't do yo thang
}

Well, what happens then is that the code just passes by without executing. If I put it in a while-sentence (while _global not new value), then the script hangs in an infinite loop.

But I found a workaround to the problem, but since its pretty particular to my code, and is of no real general value, I will not post it.

Thanks for the response, though :slight_smile: