Home   Help Search Login Register  

Author Topic: Time Spent Solved  (Read 1395 times)

0 Members and 1 Guest are viewing this topic.

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Time Spent Solved
« 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
« Last Edit: 04 Oct 2008, 07:05:20 by Luke »
Pesky Human!!
Wort Wort Wort.

Offline i0n0s

  • Former Staff
  • ****
Re: Time Spent
« Reply #1 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.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Time Spent
« Reply #2 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;
« Last Edit: 03 Oct 2008, 02:44:15 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: Time Spent
« Reply #3 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
« Last Edit: 04 Oct 2008, 01:55:21 by Luke »
Pesky Human!!
Wort Wort Wort.

Offline ModestNovice

  • Members
  • *
Re: Time Spent
« Reply #4 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;
};
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: Time Spent
« Reply #5 on: 04 Oct 2008, 01:55:41 »
Thanx.

Fixed!  :D

Luke
Pesky Human!!
Wort Wort Wort.