Jump to content

Recommended Posts

Hello!
I am trying to loop some commands within an .SQF that includes IF ELSE statements.
I need the script to loop while a certain variable is true so that the mission may later set the variable to false, disabling the script.
Here is my current script:

 

tester.sqf
____________________________________________________

_xxx3 = true;


While {_xxx3 == true} do {

sleep 1;

if (istouchingground player) then {
hint "You are on ground";

 

} else {

 

hint "Game Detected you are in water, will reset position in 3 seconds";  

sleep 3;
if (istouchingground player) then {
    hint "Not in water anymore";
    } else {
        player setpos [0,0,0]; hint "Position reset";};};

______________________________________________________
After the player has been detected in the water (or not touching ground) I have the script run another check 3 seconds afterwards to ensure that the player is actually in water and not glitching out in air for a few seconds, as is common in Arma, so that is why I have included another IF-ELSE statement below. The "sleep 1" I included in the beginning is to help minimize the impact on performance, so that the script only runs every second instead of every frame.
 

Running execvm "tester.sqf"; gives no error messages but the script does not run.  
I tried scouring the forums for a similar situation and somehow I haven't found anything. If anyone can help me out I would be very grateful, I've been stumped on this for a few days now.
Thank you!!

 

 

Share this post


Link to post
Share on other sites
someGlobalVar = TRUE;
_thisIsALocalVar = TRUE;
while {someGlobalVar} do
{
	hintSilent "Beep";
	sleep 1;
};

 

Share this post


Link to post
Share on other sites

You have missing closing curly bracket, the script won’t run at all. No worries, when you fix this you will have plenty of errors.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you @HazJ! I have adjusted my script and it is now functioning as I intended.

@killzone_kid my apologies, I failed to highlight the last bracket when I copied and pasted my code. Good eyes though, I appreciate it!

Here is my final working product for anyone referencing the thread, or if anyone else has any additional tips:

testers.sqf
_____________________________________________________________________

xxx3 = true;
While {xxx3} do {
sleep 3;

if (istouchingground player) then {
hint "You are on ground";

} else {

hint "Game Detected you are in water, will reset position in 3 seconds";
sleep 3;  
if (istouchingground player) then {
    hint "Not in water anymore";
    } else {
player setpos [0,0,0]; hint "Position reset";};};};

_____________________________________________________________________

To end this loop you can create a trigger or another .sqf that contains "xxx3 = false" and the script will end.

Thanks again for helping me solve this problem!

Share this post


Link to post
Share on other sites

HIGHLY recommend to think about indents and wise case choise.

Upper cases, lower cases and indents are never effect to actual evaluation though, readability is really important for you or any scripters.

xxx3 = true;
while {xxx3} do {
	sleep 3;
	if (isTouchingGround player) then {
		hint "You are on ground";
	} else {
		hint "Game Detected you are in water, will reset position in 3 seconds";
		sleep 3;  
		if (isTouchingGround player) then {
			hint "Not in water anymore";
		} else {
			player setPos [0,0,0];
			hint "Position reset";
		};
	};
};

 

Also, use the button with <> icon to make a code block into a forum post.

  • Like 2

Share this post


Link to post
Share on other sites

Use some sqf editor like Sublime Text 2 (Poseidon). Cherry on the cake, when your cursor is on a command/function and you strike F1, you open the BIKI documentation about it.

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

×