Jump to content
Sign in to follow this  
Drozdov

Externally Interrupting a Script

Recommended Posts

Simple question, how do you externally interrupt an already running looped script? The scenario is an AI on a searchlight with a looping script which tells him to watch a different direction (ie he targets 3 different game logics in order) every 15 seconds. He's near a town with a bunch of other friendly loons.

If he or his friends spot an enemy, what I want to happen is for him to get off his searchlight and go and join the others. Obviously that can be done easily enough, but I'm wondering how to stop the script continuing to run, causing the soldier who was on his searchlight to keep on staring out to sea. I don't know any way to properly halt the script internally - I can't see any scripting function to check if one side has detected an enemy.

I could just delete the gamelogics when a trigger detects that the enemy has been detected, but the searchlight script would still continue to run which probably isn't a good thing. I'd like some suggestion as to how to end the script as soon as an enemy is detected by anyone on the searchlight operator's side. help.gif

Share this post


Link to post
Share on other sites

You're needing the terminate command.

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

MyScriptHandle = [] execVM "MyScript.sqf";

waitUntil {ConditionToExitOn};

termintate MyScriptHandle;

Share this post


Link to post
Share on other sites

Argh, I can't get that to work.

I've tried various ways to use that and usually it just causes a CTD and tells me the preprocessor failed on my script file (error 7). I've no idea how to use sqf files, I always used sqs before. Am I supposed to use the code sample you made (I noticed the typo on terminate btw, it's not that) in a separate script or in a trigger line? Either way it seems to have the same effect. banghead.gif

Running it without the extra terminate script seems to cause it to fuck up as well now I'm using it as an sqf.

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

{

search1 dowatch t1;

Sleep 15;

};

{

search1 dowatch t2;

Sleep 15;

};

{

search1 dowatch t3;

Sleep 15;

};

{

search1 dowatch t2;

Sleep 15;

};

goto "start";

Could you please tell me why that's wrong as an .sqf script? I'm just fed up wasting ages loading up ArmA over and over again and getting the same damn error message.

Share this post


Link to post
Share on other sites
goto is not used in .sqf.

Bingo.

Use a loop instead:

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

{

search1 dowatch t1;

Sleep 15;

search1 dowatch t2;

Sleep 15;

search1 dowatch t3;

Sleep 15;

search1 dowatch t2;

Sleep 15;

};

There are much better ways of doing that than using terminate though. Try this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {alive search1} do

{

if (alive search1) then {search1 dowatch t1;};

Sleep 15;

if (alive search1) then {search1 dowatch t2;};

Sleep 15;

if (alive search1) then {search1 dowatch t3;};

Sleep 15;

if (alive search1) then {search1 dowatch t4;};

Sleep 15;

};

Or this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {alive search1} do

{

if (!(alive search1)) exitWith{""};

search1 dowatch t1;

Sleep 15;

if (!(alive search1)) exitWith{""};

search1 dowatch t2;

Sleep 15;

if (!(alive search1)) exitWith{""};

search1 dowatch t3;

Sleep 15;

if (!(alive search1)) exitWith{""};

search1 dowatch t4;

Sleep 15;

};

Or, a million other methods similiar to that.

You'll have to check the syntax on those if you use them. I just typed them on the fly.

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  

×