My question is:
* How do I call/start such a script?
-if arma2 syntax is the same as the original, type: [] execvm "script.sqf"
* How can I switch it off? It looks as if all I have to do is change a variable to false. But wich one?!?
All righty here, lets take a look at the script.
Dunno how much you know, so I'll start from the ground up.
while {true} do
{
playSound "LHD_engine";
sleep 6.8;
};
You're right about the variable being switched to false.
However, as written that's impossible.
Explanation: in a while command the condition in the braces {} must be true to loop.
When is true not true? (huh?) Never, meaning this code will loop forever.
Now if you were to change the script to say something like this:
_engine_switch = true;
while {_engine_switch} do
{
playSound "LHD_engine";
sleep 6.8;
};
you could control it.
as long as the variable _engine_switch is true it will loop.
when you run the code as I have rewritten it it will switch _engine_switch to true and loop the sound.
and since the variable has an underscore (_) in front of it, I believe that makes it a global variable.
In other words, I believe it can be switched true or false by another script.
However, as rewritten, when _engine_switch becomes false, the loop terminates, and the script needs to be re-executed to run the loop again.
Now, if it is re-written again, that won't be necessary to re-execute the script.
_engine_switch = true;
while {_engine_switch} do
{
playSound "LHD_engine";
sleep 6.8;
waituntil {_engine_switch};
};
This will stop it mid-loop if _engine_switch ever becomes false.
However, it is still technically in the "while" loop, so you won't need to execute it again.
Now for switching it on and off.
if (_engine_switch) then {_engine_switch = false} else {_engine_switch = true};
if (isnil _engine_switch) then {_engine_switch = true};
I know it's a simple and short script.
Execute the script by typing: [] execvm "engineswitcher.sqf";
That's all I can think of, and, I know, the post is long.
Anywho, hope that helps.
Luke