Jump to content
Sign in to follow this  
Jex =TE=

How do I delay a script?

Recommended Posts

Looking at the wiki and so far I have come up with the following (which doesn't work)

Quote[/b] ]

#wait

Radio1 say ["sound1",0];

waituntil { _time = 185 };

if (alive Radio1) then {goto "wait"};

I need to delay the goto until the sound file has finished playing (it's 182 seconds long) and then I want it to repeat itself. I have tried using just the "time" variable but that doesn't work. The wiki says to use "_time" when within a script.

I get "error generic error in script"

Can anyone help?

Share this post


Link to post
Share on other sites

for an sqs script, you just use ~# where # equals number in seconds.

Share this post


Link to post
Share on other sites

Just as Messiah said:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#wait

Radio1 say ["sound1",0];

~ 182;

if (alive Radio1) then {goto "wait"};

Wanna break it if the radio dies in the process of waiting as well?

Share this post


Link to post
Share on other sites
Just as Messiah said:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#wait

Radio1 say ["sound1",0];

~ 182;

if (alive Radio1) then {goto "wait"};

Wanna break it if the radio dies in the process of waiting as well?

Yep that would be great, thanks smile_o.gif

Thanks Guys!

Share this post


Link to post
Share on other sites

that doesn't work sad_o.gif

I get...

Quote[/b] ]

'_waituntil = _time+( |#|182; )'

Error Generic error in expression

When i enter the 3d world

Share this post


Link to post
Share on other sites

You're using your script instead of mine.

OK, here's my try on the sqs script.

Mind that I'm not too good with them (the semi-colons might be wrong):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#start

_time = 0;

Radio1 say ["sound1",0];

#loop

~ 1;

_time = _time +1;

if (not alive Radio1) then {goto "end"};

if (_time == 182) then {goto "start"};

goto "loop"

#end

in case you want to use sqf (which I would suggest):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

while {alive Radio1} do

{

Radio1 say ["sound1",0];

_time = 0;

while {_time < 182} do

{

sleep 1;

_time = _time + 1;

if (not alive Radio1) ExitWith {};

};

};

Share this post


Link to post
Share on other sites

Thanks for taking the time to help me out here Deadfast. I'm a total new when it comes to scripting anything and don't really understand that much.

I tried you sqf but I get this error.

'|#|sleep 1:'

Error Generic...

(the sqs also gives an error)

'_waituntil = _time+( |#|1; )'

Error Generic

I'm starting to hate scripting lol  banghead.gif

Share this post


Link to post
Share on other sites

Further to the above the sound stops when the radio dies but it doesn't loop.

Thanks again (lol you'll get credits in the mission for this - wow wink_o.gif )

Share this post


Link to post
Share on other sites

Interestingly if I remove the

~ 1;

from the SQS I don't get an error but it doesn't loop the soundtrack.

Share this post


Link to post
Share on other sites

Try this?

Haven't tested it, but it might work.

Script called "timer.sqf"

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

//plays _snd repeatedly as long as _obj is alive

_length = _this select 0;  //length of timer

_obj = _this select 1;  //object to play sound from

_snd= _this select 2;  //sound to play

_x = 0;  //internal timer variable

_obj say [_snd, 0];  //play sound

//infinite loop

while {true} do

{

  if (!alive _obj) exitWith {};  //check if _obj is dead

 

  //check if time is up

  if (_x > _length) then

  {

     _x = 0;  //reset internal timer

     _obj say [_snd, 0];  //re-play sound

  };

  _x = _x + 1;  //increment internal timer

  sleep 1;  //wait 1 second

};

if (true) exitWith {};  //exit script

I am assuming Radio1 is some sort of object (hence the "not alive"). Also, with this you can change how long till the sound is looped, what object it is played from, and what sound is played. So, putting this in it's init line would run the script:

Init of Radio1

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

nil = [182, this, "sound1"] execVM "timer.sqf";

'182' is the length of the sound file, 'this' is the object (you are in it's init line) to play the sound from, ' "sound1" ' is the sound file you wish to play, it is important to keep the quotes around it.

This code will let you use the same script for multiple sounds from multiple objects.

Let me know if anything doesn't work ... might have some errors in there ..

EDIT: Few errors fixed ...

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  

×