Home AMX User Forum AMX General Discussion

Nested WAIT or Sequential WAIT?

I am wondering if there is any benefit to nesting waits? Here is a little example:
button_event[dvtp,1]{
push:{
  do_thing(1);
  wait 5 {do_thing(2); 
  wait 5 {do_thing(3);
  wait 5 {do_thing(4);
  }}}
}
}

versus:
button_event[dvtp,1]{
push:{
  do_thing(1);
  wait 5 do_thing(2); 
  wait 10 do_thing(3);
  wait 15 do_thing(4);
}
}

Would the first one require less processor overhead as in my mind, the processor is only tracking 1 wait through the whole process?

Jeff

Comments

  • viningvining Posts: 4,368
    Spire_Jeff wrote:
    the processor is only tracking 1 wait through the whole process?
    I'd agree with that. Only one wait is in the wait queue at a time where in the other method all three waits are in queue and being checked every pass of the system timeline to see if they're ready to be executed.

    The only benefit I can see for not nesting would be if you needed the ability to cancel one wait with out affected the others. If they're nested cacelling one wait would cancel any waits nested beneath it which aren't actually "waiting" yet. They're waiting to wait. :)
  • Spire_JeffSpire_Jeff Posts: 1,917
    vining wrote: »
    The only benefit I can see for not nesting would be if you needed the ability to cancel one wait with out affected the others. If they're nested cacelling one wait would cancel any waits nested beneath it which aren't actually "waiting" yet. They're waiting to wait. :)

    That is a good point. The only thing is the canceling of nested waits.... I don't think you would be able to cancel a nested wait unless it is actually waiting at the time of cancel. If it is waiting when you cancel it, it would cancel all remaining waits. This raises an interesting thought.... what if you named all of the waits the same name? You should be able to cancel the named wait and it would cancel any wait that has not executed.

    Jeff
  • mpullinmpullin Posts: 949
    hmm what do you think this does
    DEFINE_FUNCTION doingThings(INTEGER nThing){
         if(nThing == 0) return;
         if(nThing == 1){
              doThing(1);
              return;
         }
         doThing(nThing);
         wait 5 'DOING_THINGS' doingThings(nThing-1);
         return;
    }
    
  • Spire_JeffSpire_Jeff Posts: 1,917
    Looks like it does things in countdown order with a .5 second firing rate.

    Jeff
  • viningvining Posts: 4,368
    If you cancel a wait you toss out the code block associated with that wait so that code doesn't execute. If there are waits inside of that code block being tossed it really doesn't matter cuz they're part of the code being tossed and subsequently will never get a chance to be put in the wait queue.
Sign In or Register to comment.