Home   Help Search Login Register  

Author Topic: Terminate (Solved)  (Read 2630 times)

0 Members and 1 Guest are viewing this topic.

Offline Arkon

  • Members
  • *
Terminate (Solved)
« 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:


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

Code: [Select]
_script = []execVM"yourwaitingscript.sqf";
terminate _script;

Dunno what I am doing wrong here - any ideas?

Thanks

« Last Edit: 25 Feb 2010, 16:03:45 by Arkon »

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: Terminate
« Reply #1 on: 24 Feb 2010, 08:26:00 »
maybe a little delay is needed`?

Offline Arkon

  • Members
  • *
Re: Terminate
« Reply #2 on: 24 Feb 2010, 11:55:04 »
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
Code: [Select]
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.
Quote
dummy = [] execVM "TestExecute.sqf";

This is the script
Quote
// 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.
Quote
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:
Quote
script_running = [7, 30, 50, 5, 10]execVM"mando_ghosts\ghost_mngr.sqf";

Quote
terminate script_running;

still no luck.
« Last Edit: 24 Feb 2010, 15:24:18 by Arkon »

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: Terminate
« Reply #3 on: 24 Feb 2010, 18:18:56 »
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.

Offline Arkon

  • Members
  • *
Re: Terminate
« Reply #4 on: 24 Feb 2010, 18:33:10 »

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.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Terminate
« Reply #5 on: 25 Feb 2010, 11:48:43 »
Arkon, this is the script you are trying to terminate.
Code: [Select]
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.

Offline Arkon

  • Members
  • *
Re: Terminate running script
« Reply #6 on: 25 Feb 2010, 13:07:49 »
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.
Code: [Select]
script_running = [7, 30, 50, 5, 10]execVM"mando_ghosts\ghost_mngr.sqf";
Code: [Select]
terminate script_running;
This is what I was trying to do - see below for solution:

Quote
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:
Code: [Select]
// 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
Code: [Select]
my_condition_to_exit_var = true
Thanks to Monsada for this solution

« Last Edit: 25 Feb 2010, 15:24:17 by Arkon »