OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Lean Bear on 01 Oct 2005, 19:50:38

Title: Waiting For a Variable For a Specific Time
Post by: Lean Bear 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?
Title: Re:Waiting For a Variable For a Specific Time
Post by: Platoon Patton 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"


Title: Re:Waiting For a Variable For a Specific Time
Post by: 456820 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
Title: Re:Waiting For a Variable For a Specific Time
Post by: Lean Bear 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).
Title: Re:Waiting For a Variable For a Specific Time
Post by: Platoon Patton 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.

Title: Re:Waiting For a Variable For a Specific Time
Post by: Lean Bear 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! :)
Title: Re:Waiting For a Variable For a Specific Time
Post by: Planck on 01 Oct 2005, 20:50:38
Quote
but I forget what _time does...

PP answered this above.


Planck
Title: Re:Waiting For a Variable For a Specific Time
Post by: THobson on 01 Oct 2005, 20:51:52
_time is the time since the start of the script
Title: Re:Waiting For a Variable For a Specific Time
Post by: Lean Bear 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?
Title: Re:Waiting For a Variable For a Specific Time
Post by: Triggerhappy 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...
Title: Re:Waiting For a Variable For a Specific Time
Post by: THobson 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.
Title: Re:Waiting For a Variable For a Specific Time
Post by: Lean Bear 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)