Jump to content
Sign in to follow this  
Arkon2

Terminating a script

Recommended Posts

HI,

I have been trying to terminate a script from within another script, but without success. This is what I have gleaned from other posts.

I put this in the .Ini file.

my_condition_to_exit_var = 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 running at the same time.

I also tried Mando's simple

script_running = [7, 30, 50, 5, 10]execVM"mando_ghosts\ghost_mngr.sqf";
terminate script_running;

Any ideas?

Edited by Arkon2

Share this post


Link to post
Share on other sites
uh... what´s on the other script?

Thanks for the reply...

Does not matter - script "A" ( [] execVM "genstuff.sqf"; ) is running doing whatever - when script "B" is called, then script "A" needs to terminate...

Edited by Arkon2

Share this post


Link to post
Share on other sites

You might try enclosing the

scriptDone _script_handler || my_condition_to_exit_var

in parenthesis. You need to put some hints in there to help you debug it. Is the script getting past the waitUntil? try adding a hint in there that says something like " waitUntil finished" and then a hint inside the if statement to see if it's firing etc.

Share this post


Link to post
Share on other sites

So basically, you've got two scripts running there... one to do stuff and another to kill the first one in case a condition is met or the script itself finishes right?

So, what I'm not seeing here is a script that will actually set this termination condition to true...

Will there be another script or a trigger that does it? and if I'm not mistaken, I think you would need to use globalVariable to get a script to change a variable in another script, wouldn't you?

Just a few thoughts... I hope it helps :)

Cheers

Edited by TheHarvesteR

Share this post


Link to post
Share on other sites

you must use call and gestuff must return a variable for cheking continue or not:

the best in converting genstuff in a function like this

// TestExecute.sqf;

//Inside TestExecute.sqf creates a  genstuff function
genstuff = {
private["_exit"];
_exit=true;

//put code of genstuff.sqf here


//Now evaluate if must continue or not
_exit = true;


//Returns _continue must be the last command
_exit;
};


//main of TestExecute.sqf
private["my_condition_to_exit_var"];

my_condition_to_exit_var = false;
my_condition_to_exit_var = call genstuff;


if (my_condition_to_exit_var) exitwith{};

if what you want is to kill genstuf process u need to do something diferent:

// TestExecute.sqf;

//Only need if used with spawn
genstuff = preprocessFileLineNumbers "genstuff.sqf";

//main of TestExecute.sqf
private["my_condition_to_exit_var, _handle"];

//Initialice _handle to null
_handle = 0 spawn {};
my_condition_to_exit_var = false;


_handle = execvm "genstuff.sqf";
// or with spawn
//_handle = spawn genstuff;

//code of your program
my_condition_to_exit_var = true;

if (my_condition_to_exit_var && !scriptDone _handle) then{
Terminate _handle; 
};

Edited by Monsada

Share this post


Link to post
Share on other sites

Hi Monsada, thanks for replying,

I'm looking at your second option, but cannot quite get my head round what the code is doing. (no spawn required)

Does:

my_condition_to_exit_var

Need to be put in the .ini file?

So are you saying that "TestExecute.sqf;" calls genstuff.sqf from within and then terminates it when the condition "my_condition_to_exit_var" is set to true?

Where does this go?

#//code of your program

my_condition_to_exit_var = true;

if (my_condition_to_exit_var && !scriptDone _handle) then{

Terminate _handle;

};

EDIT

Arma2 RPT file:

private["my_condition_to_exit_var, _hand>

Error position: <private["my_condition_to_exit_var, _hand>

Error Local variable in global space

And

Error in expression <my_condition_to_exit_var && !scriptDone _handle) then{>

Error position: <_handle) then{>

Error Undefined variable in expression: _handle

Error in expression <Terminate _handle; >

Error position: <_handle; >

Error Undefined variable in expression: _handle

Edited by Arkon2

Share this post


Link to post
Share on other sites

I put code without testing it sorry, I will correct that bugs

I will supose that my_condition_to_exit_var is a global variable.

// TestExecute.sqf;

//Only need if used with spawn
genstuff = preprocessFileLineNumbers "genstuff.sqf";

//main of TestExecute.sqf
private["_handle"];

//Initialice _handle to null
_handle = 0 spawn {};
my_condition_to_exit_var = false;


_handle = [] execvm "genstuff.sqf";
// or with spawn
//_handle = spawn genstuff;

//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; 
};

Share this post


Link to post
Share on other sites

Hi Monsada,

Thanks very much, it works perfectly :)

Regards

Arkon2

Share this post


Link to post
Share on other sites

Following on from this.....a further question...

I have a script running (Arty) from the mission start. I also have an observation position which I would like to set a trigger around, so that when it is clear the artillery script stops.

Does anyone have a simple way or code that I would need to add to the trigger init, so that when Opfor are not present, the script stops.

Many thanks.

BD1

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  

×