@ <RetVar/IF> wait randomly from <Var/Number> to <Var/Number> ms

This forum serves as MSCI Reference at EGOSOFT. It's Read-Only for non MSCI Group members.

Moderators: Scripting / Modding Moderators, MSCI Moderators

Locked
mark_a_condren
Posts: 1385
Joined: Wed, 3. Aug 05, 05:05
x3tc

@ <RetVar/IF> wait randomly from <Var/Number> to <Var/Number> ms

Post by mark_a_condren » Tue, 7. Sep 10, 16:47

@ [skip|else] if [not]|while [not]| <RetVar/IF> = wait randomly from <Var/Number> to <Var/Number> ms


[skip|else] if [not]|while [not]| = The possible 'Conditional' statements that can be used with this command.
<RetVar/IF> = The time remaining of the wait time entered.
<Var/Number> = The length of time to for the script to wait in milliseconds, the first one being the minimum time and the second being the maximum time to wait.


Causes the script to pause for a random length of time between <Var/Number> and <Var/Number> milliseconds.

As in the case of wait, this is approximate.

Generally it can be counted on that the delay will be at least for the specified minimum length of time.
No delay can be less than the length of time it takes for one screen refresh, see Note, so a one millisecond wait will delay until the next refresh.

Every script that runs for an indefinite period of time should include have at least one of these statements in its main loop.
This makes it very unlikely that large numbers of scripts will all become active at the same time.

The game engine will give back the hand if it has nothing better to do if you give the wait <RetVar/IF> a large value. In this case the <RetVar/IF> is supposed to be the time left to wait (an approximation I guess) to reach the values you've supplied as arguments.


Example:
  • $Loop = 0
    while $Loop < 10
    @ = wait randomly from 100 to 200 ms
    | inc $Loop =
    end


This will create an approximate 100 to 200 millisecond wait in each iteration of the 'while' statement.

To obtain the '=' without having 'null' there you select 'No return variable' from the list of possible conditional statements at the bottom of the SE menu.

----------------------------------

$ret = wait randomly from 10000 to 20000 ms

If it gives back the hand after 6 secs, then $ret should then be equal to a minimum of 4000.


----------------------------------

Caution Notes:

It's difficult to find any practical use to the IF / while statements here (the first one is unreliable, the other one has a fairly good chance to make an infinite loop).

if wait randomly from 100 to 1000 ms
| wait again ?
end

An additional note: long wait times (over a few seconds) are unreliable and should be cut in smaller ones when precision is necessary.

----------------------------------

Note:
Take the current refresh rate in frames per second and divide that into 1000 to get the number of milliseconds per frame.
This will be the minimum wait time.
A utility called 'fraps' (http://www.fraps.com) can tell you what your current frame rate is.
Of course, the frame rate in any given situation will depend on the processing power of the user's computer who is running your script.
But it's a good thing to remember that any wait placed in your script will delay for at least one frame.
For example, any wait placed inside a loop will cause the loop to iterate at most once per frame.


Command Location:

Locked

Return to “MSCI Reference”