Jump to content
Sign in to follow this  
crashdome

Sleep in Functions

Recommended Posts

OK, from my chat with Igor and his testing, I concluded that functions (using call) can use sleep to pause them.

I've yet to hear otherwise. However, DeanosBeanos and I just wrote a fucntion and it kept giving "generic error in expression" with the sleep command. We would take out the sleep command and it worked fine.

So I have conflicting results. So anyways, can anyone confirm that sleep does in fact work in a function?

My Chat with Igor

Quote[/b] ]12/18/2006 3:58 PM   Igor Drukov   call waits

12/18/2006 3:58 PM   Igor Drukov   testing conditions:

12/18/2006 3:58 PM   CrashDome   I figured

12/18/2006 3:59 PM   Igor Drukov   caller.sqf (can't be an.sqs or else you get an error with the other file)

12/18/2006 3:59 PM   Igor Drukov   private ["_i","_j","_t"];

_i=0;

_j=0;

while {_i < 10} do {_i=_i+1;_t=[] execVM "test.sqf";_j=_j + _t;};

hint format ["%1",_j]

12/18/2006 3:59 PM   Igor Drukov   test.sqf

12/18/2006 3:59 PM   Igor Drukov   sorry replace execVM by call

12/18/2006 3:59 PM   Igor Drukov   private ["_i"];

_i=0;

while {_i<9} do {sleep 0.1;_i=_i+1};

_i

12/18/2006 4:00 PM   Igor Drukov   caller will halt until it gets the proper vlue

12/18/2006 4:00 PM   Igor Drukov   so in tjhis example it takes about ten seconds to get the hint

12/18/2006 4:01 PM   Igor Drukov   can you briefly explain to me how to use scriptDone?

12/18/2006 4:03 PM   Igor Drukov   nevermind i'll global variable it smile_o.gif

12/18/2006 4:06 PM   Igor Drukov   execVM doesn't wait

12/18/2006 4:06 PM   Igor Drukov   testing conditions:

12/18/2006 4:06 PM   Igor Drukov   global variable gh set to 0 from the init.sqf

12/18/2006 4:06 PM   Igor Drukov   caller.sqf

12/18/2006 4:06 PM   Igor Drukov   private ["_i","_j","_t"];

_i=0;

_j=0;

while {_i < 10} do {_i=_i+1;_t=[] execVM "test.sqf";};

hint format ["%1",gh]

12/18/2006 4:07 PM   Igor Drukov   test.qsqf

12/18/2006 4:07 PM   Igor Drukov   private ["_i"];

_i=0;

while {_i<9} do {sleep 0.1;gh=gh+1;_i=_i+1};

_i

12/18/2006 4:07 PM   Igor Drukov   you get a hint immediately of gh=0

12/18/2006 4:08 PM   Igor Drukov   this is also true if you remove the sleep command from the test.sqf

12/18/2006 4:08 PM   Igor Drukov   tests with spawn to follow...

12/18/2006 4:10 PM   Igor Drukov   spawn doesn't wait either

12/18/2006 4:10 PM   Igor Drukov   same testing conditions, tested with and without sleep

12/18/2006 4:10 PM   Igor Drukov   only call returns 90, with or without sleep

12/18/2006 4:11 PM   Igor Drukov   so call gives priority to the code it executes then

12/18/2006 4:12 PM   Igor Drukov   well this somehow fits not so badly in my gradient theory after all

12/18/2006 4:12 PM   CrashDome   well, it's actually more simple than that

12/18/2006 4:12 PM   CrashDome   the call command exeutes code and expects a return value. It does halt engine code *unless* it hits a sleep or waituntil command

12/18/2006 4:13 PM   CrashDome   in which case the function AND script are halted

12/18/2006 4:13 PM   CrashDome   until it can finish processing that call command

12/18/2006 4:13 PM   Igor Drukov   yes

12/18/2006 4:13 PM   CrashDome   everything else runs in parallel

My Function to DeanosBeanos which gives #sleep generic error in expression

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_array","_unit"];

_array = _this select 0;

_unit = _this select 1;

{

  _unit doWatch _x;

  sleep 3;

} foreach _array;

true

As a side note, we replaced call with spawn and used:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _handle = [_array,_unit] spawn DoWatchDelay

waitUntil (scriptDone _handle) and the waituntil command said "error type:bool expected code" - is this because the original script is an SQS script? should we have just used @ instead? does waitUntil only work in SQF syntax?

Share this post


Link to post
Share on other sites
Quote[/b] ] and the waituntil command said "error type:bool expected code" - is this because the original script is an SQS script? should we have just used @ instead? does waitUntil only work in SQF syntax?

Got that right, waitUntill will not work in a sqs, dunno about the rest.. havnt the time to learn sqf considering it took me full 3 years to learn sqs scripting huh.gif

Share this post


Link to post
Share on other sites

Check my comment here.

So sleep HAS TO work when called from sqf scripts, but definitely not works when called from sqs scripts, at least if I got that right (/edit: Maybe forEach was a bad choice, it's possible that sleep does not work there anyway).

@Your scripts: waituntil expects code, made that mistake just some days ago:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">waitUntil {scriptDone _handle}

Share this post


Link to post
Share on other sites
Quote[/b] ]

My Function to DeanosBeanos which gives #sleep generic error in expression

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_array","_unit"];

_array = _this select 0;

_unit = _this select 1;

{

 _unit doWatch _x;

 sleep 3;

} foreach _array;

true

I just tried your function, it works fine with the call command. When you first tested it, how did you call the function? Via exec, execVM e.t.c, a trigger or a units init field?

Share this post


Link to post
Share on other sites

I'm guessing it falls into the realm of some sort of typo or weird characters maybe??

I even had given ofpforum an FSM to test and it was throwing errors and we found out that the " marks were wrong somehow? like a unicode character problem or something.....

Hmm.. thanks for verifying though. I was about to freak.

and thanks for the heads up with waitUntil, raedor!

Share this post


Link to post
Share on other sites
Quote[/b] ]I'm guessing it falls into the realm of some sort of typo or weird characters maybe??

If you called your function directly from a units init field, then that will cause sleep to throw up an error to.

Quote[/b] ]I even had given ofpforum an FSM to test and it was throwing errors and we found out that the " marks were wrong somehow? like a unicode character problem or something.....

I've had similar problems with configs in the past, it's a nightmare to track down if your not expecting it.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×