OFPEC Forum
Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: Arkon on 24 Feb 2010, 01:15:17
-
Hi, I have read a few posts regarding the Terminate command - I am trying to terminate a script from within another script, but without any success. here is a couple of Mando's I tried:
script_running = [7, 30, 50, 5, 10]execVM"mando_ghosts\ghost_mngr.sqf";
terminate script_running;
_script = []execVM"yourwaitingscript.sqf";
terminate _script;
Dunno what I am doing wrong here - any ideas?
Thanks
-
maybe a little delay is needed`?
-
Ok kju, thanks for that, but here is my latest try - this is the code i have been using: mostly gleaned from previous posts.
This is in the .Ini file
my_condition_to_exit_var2 = false;
This is what I call the script with - I run this close to when I want to exit the target script.
dummy = [] execVM "TestExecute.sqf";
This is the script
// TestExecute.sqf;
my_condition_to_exit_var = false;
_script_handler = [] execVM "genstuff.sqf";
waitUntil {scriptDone _script_handler || my_condition_to_exit_var};
if (my_condition_to_exit_var && !(scriptDone _script_handler)) then
{
terminate _script_handler;
};
This is the line for termination - I put this at the start of another script so when the script is called it will terminate the target script.
my_condition_to_exit_var = true
Nothing seems to happen - both scripts are still running at the same time.
I also tried Mando's simpler:
script_running = [7, 30, 50, 5, 10]execVM"mando_ghosts\ghost_mngr.sqf";
terminate script_running;
still no luck.
-
Why do want to use terminate?
There are other ways to design code to achieve the same.
The dangerous part about terminate is that you have no idea in what state you stopped the script.
This may or may not be a problem depending on the situation.
-
Hi, kju
Thanks for the reply,
Firstly, These are long scripts involving moving quite a few people and objects about - the main thing is that an officer is the key part in the first script inspecting troops etc - He might be killed whilst all this is going on and that is when the second script needs to be run to reflect behaviourial changes around him. So I just want to get out of the first script as soon as possible. For flexibility I may need to exit from more than one different script, but only one at a time.
-
Arkon, this is the script you are trying to terminate.
ghost_parms = "";
_maxspd = _this select 0;
_mindist = _this select 1;
_maxdist = _this select 2;
_mindelay = _this select 3;
_maxdelay = _this select 4;
[_maxspd, _mindist, _maxdist, _mindelay, _maxdelay]execVM"mando_ghosts\mando_ghosts.sqf";
while {true} do
{
waitUntil {ghost_parms != ""};
(call compile ghost_parms) execVM "mando_ghosts\draw_ghost.sqf";
ghost_parms = "";
};
When you terminate it, the while will stop, but any running instances of draw_ghost.sqf will keep running.
-
Hi, Mandoble,
Thanks for the reply.
Sorry but I think I have got my lines crossed here as I was just showing this code (below) as an simpler example of what I was trying to do.
script_running = [7, 30, 50, 5, 10]execVM"mando_ghosts\ghost_mngr.sqf";terminate script_running;
This is what I was trying to do - see below for solution:
These are long scripts involving moving quite a few people and objects about - the main thing is that an officer is the key part in the first script inspecting troops etc - He might be killed whilst all this is going on and that is when the second script needs to be run to reflect behaviourial changes around him. So I just want to get out of the first script as soon as possible. Also I may need to have the option of exiting any one of a few different scripts which might be running when the officer is shot.
Solution:
// TestExecute.sqf;
//Only need if used with spawn
genstuff = preprocessFileLineNumbers "exitfrom.sqf";
//main of TestExecute.sqf
private["_handle"];
//Initialice _handle to null
_handle = 0 spawn {};
my_condition_to_exit_var = false;
_handle = [] execvm "exitfrom.sqf";
// or with spawn
//_handle = spawn exitfrom;
//we wait until my_condition_to_exit_var or scritpdone.
waitUntil {scriptDone _handle || my_condition_to_exit_var};
if (my_condition_to_exit_var && !scriptDone _handle) then {
Terminate _handle;
};
Then just set this var when you want to terminate "exitfrom.sqf" script
my_condition_to_exit_var = true
Thanks to Monsada for this solution