Jump to content
Sign in to follow this  
jcae2798

While with If/Then

Recommended Posts

Sorry i know this was probably posted before, but searching didnt exactly give me the answer i need.

 

My script is below.  It is working, but what it is not doing is running through the If/Then on every loop.

 

So for example, i want it to loop every 25 seconds, and after those 25 seconds, i want to restart the If/Then checks.  However it seems to only check the condition at start and replay the same code over and over every sleep command.  Thoughts?  Hopefully i made sense and clear enough

_FAR = player distance BROTHER > 5000;
_MID = player distance BROTHER == 2500;  //Shouldnt matter as long as its between FAR and NEAR
_NEAR = player distance BROTHER < 2000;


while {alive player} do {
Sleep 25;

If (_FAR) then
{
playSound "LongRange";
hint 'LongRange';
	
	} else {
		if (_NEAR)then {playSound "ShortRange"; hint 'ShortRange';} else {playSound "MidRange"; hint 'MidRange';};
		
		};

};

Share this post


Link to post
Share on other sites

Move the top section INSIDE your 'while loop' so it knows what you are referring to each loop.

Share this post


Link to post
Share on other sites

LOL.  i knew it.  Something silly...  :)

 

Thanks man!

Share this post


Link to post
Share on other sites

hey,

 

you could do this with a switch instead of if evalutaion

 

so you only have to make 1 evaluation each cycle and compare them with the values

 

greetings :-)

  • Like 1

Share this post


Link to post
Share on other sites

cthulhu616 is right, try this

switch (true) do {
    case ((player distance BROTHER)>5000): {
        playSound "LongRange";
        hint "LongRange";
    };
    case ((player distance BROTHER)>2450) && ((player distance BROTHER)<2550): {
        //code..
    };
};

Made with KK's SQF to BBCode Converter

 

  • Like 1

Share this post


Link to post
Share on other sites

Interesting....i'll give this a whirl.  I assume this will improve performance (even though for this script it might be minimal...)

 

Thanks again guys,always helpful

Share this post


Link to post
Share on other sites

might be minimal for this, but now you know that there are other ways for evaluation aswell ;-)

 

btw... instead of

switch (true) do {
    case ((player distance BROTHER)>5000): {
        playSound "LongRange";
        hint "LongRange";
    };
    case ((player distance BROTHER)>2450) && ((player distance BROTHER)<2550): {
        //code..
    };
};

 you could also do this:

_distance= player distance BROTHER

switch (true) do {
    case (_distance>5000): {
        playSound "LongRange";
        hint "LongRange";
    };
    case (_distance>2450) && ((player distance BROTHER)<2550): {
        //code..
    };
};

so you only have to use that distance command once :-)

 

 

PS: It's all about being lazy :D

  • Like 1

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  

×