Jump to content
Sign in to follow this  
Andy455

Help with timer script

Recommended Posts

Ok so I have a little problem with this here script:

_time = _this select 0;

#Start
~1
_time=_time-1;
_timer = round (_time / 60);
hint format["Time left: %1 minutes", _timer];
if (_time > 0) then {goto "Start"} else {if (HostageFound = false) then {brianhendersson setDamage 1} else {exit};

exit;

I call it using this in the init.sqf:

[10] exec "timer.sqs";

The low number is just for testing purposes at the moment. My main problem is that the timer does not seem to count down at all (even when I remove "_time / 60" so that it shows seconds rather than minutes) and the setdamage does not work after the defined 10 seconds.

All names and variables are named correctly, I can't seem to figure this one out :( Any help would be appreciated

Andy

Share this post


Link to post
Share on other sites

_time is a reserved local variable for timekeeping within a script. Rename it to _timeleft or similar.

Change (HostageFound = false) to !(HostageFound). A single = doesn't return a value, it changes it.

Edited by Celery

Share this post


Link to post
Share on other sites

First off, thanks for the reply.

Now I still have a problem with the guy not dying when time is up and he isnt found.

Current code:

_timel = _this select 0;

#Start
~1
_timel=_timel-1;
_timer = round (_timel / 60);
hint format["Time left: %1 minutes", _timer];
if (_time > 0) then {goto "Start"} else {if (!HostageFound) then {brianhendersson setDamage 1} else {exit}};

exit;

HostageFound is defined as false in the init.sqf and later changed to true when I find the hostage (The finding part works fine just so you know).

Any ideas?

I changed HostageFound to a number ('1') rather than a true / false and used 'HostageFound > 0' as the condition and it still didnt work. The script counts down fine it just doesnt go and do the second IF statement. :(

Edited by Andy455
Adding more info

Share this post


Link to post
Share on other sites

how about make it more fancy and write it in Sqf :)

something you can work on ;)

// [min] execvm "timer.sqf";


_tn = time;
_timer = (_this select 0) * 60; // make input minutes to seconds.
_tte = _tn + _timer;
_timerstate = true;

while {(_timerstate)} do
{
sleep 0.5;
_timeRemein = (_tte - time);
switch (true) do
{
	case ((_timeRemein > 60) && (_timeRemein < 3600)) :
	{
		hint format ["Time left: %1 Minutes", (_timeRemein / 60)];
	};
	case (_timeRemein < 60) :
	{
		hint format ["Time left: %1 Seconds", (_timeRemein)];
	};
	default 
	{
		hint format ["Time left: %1 Houers", ((_timeRemein / 60)/60)];
	};
};
if (_timeRemein < 0) then {_timerstate = false;};
[b]        or[/b]
if (_timeRemein < 0) EXITWITH {};
};

Edited by nuxil

Share this post


Link to post
Share on other sites

Well thank you for your reply but that code that you posted does not seem to do anything at all :( it doesnt show any hint ever.

timer.sqf:

// [min] execvm "timer.sqf";


_tn = time;
_timer = (_this select 0) * 60; // make input minutes to seconds.
_tte = _tn + _timer;
_timerstate = true;

while {(_timerstate)} do
{
sleep 0.5;
_timeRemaining = (_tte - time);
switch (true) do
{
	case ((_timeRemaining > 60) && (_timeRemaining < 3600)) :
	{
		hint format ["Time left: %1 Minutes", (_timeRemaining / 60)];
	};
	case (_timeRemaining < 60) :
	{
		hint format ["Time left: %1 Seconds", (_timeRemaining)];
	};
	default 
	{
		hint format ["Time left: %1 Hours", ((_timeRemaining / 60)/60)];
	};
};
if ((_timeRemaining < 0) && (HostageFound < 1) then {_timerstate = false; brianhendersson setDamage 1;};

};

init.sqf:

[1] execvm "timer.sqf";

And noting happens at all, no hint no death :( Have I changed something by accident?

On a side not I have put the timer.sqf in the main folder so I did execute the right path i think.

Share this post


Link to post
Share on other sites

it works fine here..

i just did double check it.. and it works,

i tested it with a trigger.

on act test = [1] execvm "timer.sqf";

you must be doing something else wrong

oh. i think i know you problem :)

time does return the mount of time since the mission started...

it might be null since the init file is loaded before the mission starts.

you might need to do

sleep 1;

_timer = [1] execvm "timer.sqf";

or put sleep 1; on top of timer.sqf

you might also want to put switch (_timeRemein > 0) do instead of true

Edited by nuxil

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  

×