Jump to content
Sign in to follow this  
darkxess

How to exit a looping script?

Recommended Posts

Ok, I have successfully got my AI chopper to shoot chaffs on hitting a trigger,

but the thing is it just keeps shooting them like... forever! lol

if I setup a 2nd trigger to stop the looping script, how could I do it please?

This is what ive got so far:

cmflare = {


while {alive heli1} do {
       sleep 1;
       heli1 action ["useWeapon", heli1, driver heli1, 0];

  };
};
call cmflare;

And its working great, just need it to stop ... lol

Thanks guys

Share this post


Link to post
Share on other sites

Put the sleep in the while statement too

while {sleep 1;alive heli1}

If you're using script handles _myScript = [] call "Bahblah"

Then you could try using this

http://community.bistudio.com/wiki/terminate

Not had a chance to test the terminate command yet as I generally use exitWith to exit scopes and put my scripts into a wait status.

Share this post


Link to post
Share on other sites

Can someone show me a working example as im not 100% perfect in putting scripts together, thanks.

Share this post


Link to post
Share on other sites

How about using some other logic lets call it "target" place it on the map and put this:

cmflare = {
   	while {alive heli1 && (heli1 distance target < 1000)} do {
       sleep 1;
       heli1 action ["useWeapon", heli1, driver heli1, 0];

  };
};
call cmflare;

Now it will shot flares only when it closer then 1000 meters from the logic.

Share this post


Link to post
Share on other sites

I just tried that, put the logic and named it target, put in the code you put and didnt work!

The chaffs just kept coming as before, lol. Unless I did it wrong, examples or an example mission would be great.

Thanks

Share this post


Link to post
Share on other sites

Just either tinker with the distance (like set it to within 200m), or limit the amount of loops with for example:

for "_i" from 0 to 5 step 1 do
{
   sleep 1;
   if (alive heli1) do
   {
       heli1 action ["useWeapon", heli1, driver heli1, 0];
   };
};

That should shoot a short and limited series of flares, if the helicopter is alive.

Share this post


Link to post
Share on other sites

Ok ive done it with logic, and its still not perfect! its still doing it for ages when I just want it to shoot lets say 4/5 sets of

chaffs where there is either a trigger or game logic target, and stop! but its constant. Its set at 1000m but when i do 200m whatever nothing happens.

Here is the example mission ive got so far: Download Link.

Share this post


Link to post
Share on other sites
Just do what Inkompetent said.

Why would I be asking for help if I can do it myself? please... ive said already

that my scripting knowledge isnt 100% perfect, this im having trouble with.

Ive gone all the way from 100m to 1000m and only 1000m works but its still

constant which I dont want!!! so you see, im having trouble which I cant do

anything about, I wouldnt ask for help otherwise.

Share this post


Link to post
Share on other sites

I think he's suggesting my for-loop, which has nothing to do with gamelogics and distance ;)

Share this post


Link to post
Share on other sites
I think he's suggesting my for-loop, which has nothing to do with gamelogics and distance ;)

Inkompetent can you take a look at the example mission and see what is the problem please? ive tried everything and this is bugging me now, lol.

Thanks

Share this post


Link to post
Share on other sites

this will make the script run as long as heli1 is alive and timecount is less than 5, wich starts at 0 and will +1 each second based on your sleep and so script runs 5 seconds.

Edit: (activates weapon 5 times total)

cmflare = {
  _timeCount = 0;

  while {alive heli1 AND _timeCount < 5} do {
     sleep 1;
     heli1 action ["useWeapon", heli1, driver heli1, 0];
     _timeCount = _timeCount + 1;
  };
};
call cmflare;

you can also do distance instead:

replacing

_timeCount < 5

with

(heli1 distance triggername) < 100

and remove both _timeCount = 0; and _timeCount = _timeCount + 1;

That means as long as heli1 is alive and less than 100 meters from triggername center script will run.

Edited by Demonized

Share this post


Link to post
Share on other sites

just a note i would have placed the sleep line after the action incase heli1 is killed in the second before action is taken.

Very low chance but it can happen and create an error.

If you need a second for the first run simply place a sleep before the while line:

cmflare = {
  _timeCount = 0;

  sleep 1;  // optional sleep if needed before first action.
  while {alive heli1 AND _timeCount < 5} do {
     heli1 action ["useWeapon", heli1, driver heli1, 0];
     _timeCount = _timeCount + 1;
     sleep 1;
  };
};
call cmflare;  

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  

×