Jump to content
Sign in to follow this  
jcae2798

IF/While stopping the script

Recommended Posts

Hey guys,

Have the following code within a script and it's not allowing the script to runn 100% of the time. Any ideas if i am doing something wrong?

Example:

	
_unit 				= _this select 0;
_buildings = [_unit,70] call SBGF_fnc_buildingPositions;
_maxWaitTime 		= 30;
_unit setbehaviour "SAFE";
sleep 1;
hint 'script runing';

while {alive _unit} do {
_b = behaviour _unit; 
hint _b;  //It is returning SAFE so i know its not COMBAT and should be running!
while {_b == "COMBAT"} exitwith {hint 'exited'};
//sleep (random 15);
_rndPos = (_buildings select 1) call BIS_fnc_selectRandom;
_waitTime = floor(random _maxWaitTime);
_unit setBehaviour "SAFE";
_unit setSpeedMode "LIMITED";
_unit doMove _rndPos;
_unit setSpeedMode "LIMITED";
sleep 0.5;
_timeout = time + 50;
waitUntil {moveToCompleted _unit || moveToFailed _unit || !alive _unit || _timeout < time};

sleep _waitTime;
};

If i comment out the following line it seems to run 100% correctly on all units:

while {_b == "COMBAT"} exitwith {hint 'exited'};

Stumped....

Share this post


Link to post
Share on other sites

Sorry i should have mentioned i also tried:

"If {_b == "COMBAT"} exitwith {hint 'exited'};" AND "If {_b == "COMBAT"} exitwith {};"

My guess is my condition is broken? (_b == "COMBAT")?

Share this post


Link to post
Share on other sites

Hey Killzone. I'm not sure i follow. Sorry i have come a long way learning the scripting language, but i am still nowhere near at novice level yet. What do you mean? Isnt that what i am doing? I guess my original post i put the latest test which was "WHILE" but i am mostly testing the IF EXITWITH statements:

If {_b == "COMBAT"} exitwith {};

---------- Post added at 16:37 ---------- Previous post was at 16:36 ----------

Also just tried:

If {_b isEqualTo "COMBAT"} exitWith {hint 'exited'};

with no luck....

Share this post


Link to post
Share on other sites

AHHHHH, i think i got it now:

while {alive _unit} do {
_b = behaviour _unit; 
hint _b;
While {_b isEqualTo "COMBAT"} do {hint 'exited'};
...rest of code...

Do i got it right now? If so i understand now, you can mix IF with WHILE unless you only want to exit IF/THEN statment... Otherwise i'm still lost lol

---------- Post added at 16:41 ---------- Previous post was at 16:40 ----------

Wow, you know i didnt notice i used "{" instead of "(" Duh. I'll try this too! Thank you.

Share this post


Link to post
Share on other sites

exitWith is used in conjunction with an if statement, not while.

Your exitWith statement has to be within the overall while loop, to then exit the while loop:

while {condition} do 
{
   if (condition) exitWith {hint "loop ended";};
};
//rest of code...

Edited by JShock

Share this post


Link to post
Share on other sites

lol....i should think about the codes a bit more before testing them sometimes... I tried the

While {_b isEqualTo "COMBAT"} do {hint 'exited'};

and completely locked up my PC i'm sure you understand why. :P

Yes going to try the IF again, but this time using the "()" instead of brackets {}. I feel foolish for missing that

Share this post


Link to post
Share on other sites
I feel foolish for missing that

No worries,

once you got the basics covered it's time for the real scripting nightmares to begin.

They're already lurking.

:yay:

Cheers

Share this post


Link to post
Share on other sites
Consider using scopeName and breakTo and breakOut.

That's what I would consider an unclean way of doing things, I've honestly never seen anyone use that in any of the code that I've ever seen for Arma 3.

Edited by JShock

Share this post


Link to post
Share on other sites

Hi J,

breakTo etc is handy if you want to exit multiple scopes, wheras exitWith will only exit the current scope. I use it all the time in A2 (and A3).

I guess you could exitWith and give some variable that every scope checks to exitWith down to where you need to be but that's more messy imo.

Share this post


Link to post
Share on other sites
Say WHAT???

Ok, bad choice of a word, so what, I've just never like using them.

Hey Das, yea I know what their used for, and could be used for, but I've just never had a situation in which I needed to use them, or at least I preferred a different method when I could have used them :p.

Share this post


Link to post
Share on other sites
Ok, bad choice of a word, so what, I've just never like using them.

Bad choice of everything. Your personal choice is your personal choice, don't try to make it as if this is how everyone should do it. breakOut with return value is by far the best thing that happened to SQF since OFP.

Share this post


Link to post
Share on other sites
Bad choice of everything. Your personal choice is your personal choice, don't try to make it as if this is how everyone should do it. breakOut with return value is by far the best thing that happened to SQF since OFP.

No one has to listen to me, but I'm surely honored that you think that my words have the power to will people into doing something :D.

Share this post


Link to post
Share on other sites
No one has to listen to me, but I'm surely honored that you think that my words have the power to will people into doing something :D.

Unfortunately, this forum is full of newbies, that don't know better. As for me, don't kid yourself, you are barely scraping the bottom on my "people that are good at sqf" list.

Share this post


Link to post
Share on other sites
As for me, don't kid yourself, you are barely scraping the bottom on my "people that are good at sqf" list.

Thanks appreciate the complement.

Share this post


Link to post
Share on other sites

Haha, well big thanks to JShock. I use his scripts all the time and have been putting this mission design for sometime now with the help of you guys, so i appreciate the assistance/support. I dont think it's going to be this big "WOW" mission type, but i think its pretty cool and hope people will enjoy it (like you guys too!). Thanks all

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  

×