Jump to content
Sign in to follow this  
dmarkwick

General loop coding question

Recommended Posts

I need to write a loop that executes for a set amount of time, not a set amount of loops. Within this loop is another loop that just goes round and round.

1. Can the time loop be done?

2. Will the endless loop quit at the end of the time?

Needs to look something like this:

Do for x seconds

{loop indefinitely

{code for "endless" loop

sleep n

}

}

It looks pretty stupid IMO, but that's what the question is for wink_o.gif I cannot rely on the Sleep n as the value will be changing, so I cannot simply work out how many "n"s there are in "s". "s" itself is not fixed either.

All this is because I need to translate setParticleRandom, setParticleParams, setParticleCircle and setDropInterval code to Drop code.

Share this post


Link to post
Share on other sites

I do believe _time is a reserved variable that specifies how long (in seconds) the script has been running.

[edit]

Biki says _time does not work with execVM... so maybe use SQS script.

Share this post


Link to post
Share on other sites
Biki says _time does not work with execVM... so maybe use SQS script.

You can use time (without the underscore), as the Wiki says: it returns the time elapsed since mission started (in seconds).

So you can do something like this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_timeout"];

_timeout = time + 30; // the loop will be running 30 seconds

while {time < _timeout} do {

...do something...

sleep 0.5;

}

Share this post


Link to post
Share on other sites
Biki says _time does not work with execVM... so maybe use SQS script.

You can use time (without the underscore), as the Wiki says: it returns the time elapsed since mission started (in seconds).

So you can do something like this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_timeout"];

_timeout = time + 30; // the loop will be running 30 seconds

while {time < _timeout} do {

...do something...

sleep 0.5;

}

So simple and yet so genius!

I spawned a script which added a value each second...

Took me ~1hr to make that work!

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  

×