OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Luke on 03 Oct 2008, 01:50:56

Title: Time Spent Solved
Post by: Luke on 03 Oct 2008, 01:50:56
How does one find a time value and insert that constantly updating value into a script function? (sorry)

for the kinematic equation v=v(sub o) + at;

where v is final velocity, v(sub o) is initial velocity, a is an acceleration scalar, and t is time in seconds since the script began.

If any one can help, please!

Luke
Title: Re: Time Spent
Post by: i0n0s on 03 Oct 2008, 02:08:27
In a function?
A function doesn't accept sleep, waitUntil etc., so that time will be zero.
In a script: _time.
Title: Re: Time Spent
Post by: Spooner on 03 Oct 2008, 02:29:28
No, it is a common misconception that a function (i.e. SQF) doesn't allow you to sleep/waitUntil. There is nothing like something being written down on the BIKI to convince every scripter in the world of its truth ;P In fact, sleep/waitUntil can only be used in functions!

It is only event handler functions that do not allow sleep or waitUntil (for the technically minded, this is standard practice in implementing software event handlers: you run all event handlers using a single thread consecutively, rather than with lots of threads concurrently, so you don't have to start up lots of threads every time an event occurs. If you allowed pauses in this system, then other event handlers would be delayed and one of the key traits of events is that they are timely). Even then, you can just spawn a new function from inside the handler to use sleep/waitUntil as much as you want.

You get to use _time (time the script, not the mission, has run) in a script (SQS run with exec), but in a function (SQF run with call/spawn/execVM) you just have access to time (time since start of mission):
Code: (working out time since a function started) [Select]
_startTime = time;
...
_timeInFunction = time - _startTime;
Title: Re: Time Spent
Post by: Luke on 03 Oct 2008, 04:18:25
I tried hint format ["%1",time]; but got a scalar.

Found a workaround though.

Code: [Select]
_t= daytime;
while {condition} do
{
_t= ((((daytime-_t) mod 1) * 60) mod 1) *60;
hint format ["%1",_t];
sleep _a_while;
};

Luke
Title: Re: Time Spent
Post by: ModestNovice on 04 Oct 2008, 01:36:27
ummm you messed a bit of it up, ur mixing sqs and sqf.

the command ~ to delay in sqs, where as sleep is delay in sqf.
also, you must end sections in a };

Code: [Select]
_t= daytime;

while {codition} do
{
_t= ((((daytime-_t) mod 1) * 60) mod 1) *60);
hint format ["%1",_t];
Sleep _a_while;
};
Title: Re: Time Spent
Post by: Luke on 04 Oct 2008, 01:55:41
Thanx.

Fixed!  :D

Luke