Home   Help Search Login Register  

Author Topic: Waiting For a Variable For a Specific Time  (Read 833 times)

0 Members and 1 Guest are viewing this topic.

Lean Bear

  • Guest
Waiting For a Variable For a Specific Time
« on: 01 Oct 2005, 19:50:38 »
OK, basically in a script I'd like to use the "wait for condition" command '@' for a certain amount of time, say 2 secs, before continuing with the script.

For example:

@(unitDead) // waiting for this variable to be true
...blah blah _unit blah.. // What happens when the variable is true
...more code stuff...
...yackety shamekty...
unitDead = false // reset the variable

#SkipToHere

goto "NextLabel"


I guessing that adapting the @ command isn't possible, so I was wondering if there was a way to do something simple that had the same effect, but only for 2 seconds instead of waiting until the variable is true.

Can I just skip to "SkipToHere" if the variable is still false after 2 seconds?

Offline Platoon Patton

  • Members
  • *
  • "Barbecue" CreateVehicle getpos LLama
Re:Waiting For a Variable For a Specific Time
« Reply #1 on: 01 Oct 2005, 20:19:20 »
Donno if this is what u look for:

   _TimeNow = _time  

@(unitDead)    or ((_Timenow + 2)<_time)
  // waiting for this variable to be true    OR 2 seconds delay

   ?((_Timenow + 2)<_time):goto "SkipToHere"    
...blah blah _unit blah.. // What happens when the variable is true
...more code stuff...
...yackety shamekty...
unitDead = false // reset the variable

#SkipToHere

goto "NextLabel"


http://www.platoon-clan.com/ We always wellcome dedicated OFP players :)

http://www.european-combat-league.com/index.php To play with us in the best OFP league ;)

Offline 456820

  • Contributing Member
  • **
Re:Waiting For a Variable For a Specific Time
« Reply #2 on: 01 Oct 2005, 20:21:36 »
you could use a loop like this

#loop
? variable is true : goto "next"
_loopcount = _loopcount +1
? _loopcount >= 2 : goto "variable still false"
~1
goto "loop"


that should work change the parts needed to what you need
theres probaly an easier way though

Lean Bear

  • Guest
Re:Waiting For a Variable For a Specific Time
« Reply #3 on: 01 Oct 2005, 20:26:51 »
@ Platoon Patton

Perhaps, if you mean literaly doing what you put in:

_TimeNow = _time  

@(unitDead) || ((_Timenow + 2)< _time)
  // waiting for this variable to be true    OR 2 seconds delay

?((_Timenow + 2)< _time) : goto "SkipToHere"    


Does OFP read the +2 on a time value as seconds or what?

Also, I wasn't aware that using 'or' with '@' actually worked, so thanks for that info anyway ;)

@ 456820

A loop has always been an option for me, but I don't really like them, they're so messy and with an already long and complex script I was hoping to find a simpler method, like only adding one or two extra lines. (This will be reapeated a few times throughout the script).
« Last Edit: 01 Oct 2005, 20:27:27 by Lean Bear »

Offline Platoon Patton

  • Members
  • *
  • "Barbecue" CreateVehicle getpos LLama
Re:Waiting For a Variable For a Specific Time
« Reply #4 on: 01 Oct 2005, 20:33:55 »
Quote
Does OFP read the +2 on a time value as seconds or what?

Yep,_time gives the time elapsed since the script started in seconds.

http://www.platoon-clan.com/ We always wellcome dedicated OFP players :)

http://www.european-combat-league.com/index.php To play with us in the best OFP league ;)

Lean Bear

  • Guest
Re:Waiting For a Variable For a Specific Time
« Reply #5 on: 01 Oct 2005, 20:43:05 »
OK, I'm a little confused now...

There's 'time' and then there's '_time'.

I know that time will return the game time since the mission began, but I forget what _time does... :-\

Apart from that, great! :)

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Waiting For a Variable For a Specific Time
« Reply #6 on: 01 Oct 2005, 20:50:38 »
Quote
but I forget what _time does...

PP answered this above.


Planck
I know a little about a lot, and a lot about a little.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Waiting For a Variable For a Specific Time
« Reply #7 on: 01 Oct 2005, 20:51:52 »
_time is the time since the start of the script

Lean Bear

  • Guest
Re:Waiting For a Variable For a Specific Time
« Reply #8 on: 01 Oct 2005, 20:53:49 »
Oh right, yeah...whoops :P

time = elapsed time since mission start

_time = elapsed time since script start

got it, thanks ;)

edit

Just out of curiosity, is there any advantage to using either one in this situation?
« Last Edit: 01 Oct 2005, 20:54:38 by Lean Bear »

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Waiting For a Variable For a Specific Time
« Reply #9 on: 02 Oct 2005, 05:06:43 »
not really any difference i don't think, but generally i would opt for the one that goes with everything else (i.e. _time, pertaining the the script) though you could probably use both...

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Waiting For a Variable For a Specific Time
« Reply #10 on: 02 Oct 2005, 11:25:31 »
time has (or at least used to have) a bug that it was reset to zero when a saved mission is restarted.  I have not seen any reports of _time having the same problem.  I always use _time for that reason.
« Last Edit: 02 Oct 2005, 11:25:43 by THobson »

Lean Bear

  • Guest
Re:Waiting For a Variable For a Specific Time
« Reply #11 on: 02 Oct 2005, 18:26:22 »
OK, you've sold me. I'll stick with _time here. Although, in this case, it wouldn't matter if the time count was reset to zero as I just use it as a point to relate other events from in relation to each other, not to the mission time.

Thanks a bunch 8)
« Last Edit: 02 Oct 2005, 18:27:08 by Lean Bear »