Max2 0 Posted January 19, 2019 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
HazJ 1289 Posted January 19, 2019 someGlobalVar = TRUE; _thisIsALocalVar = TRUE; while {someGlobalVar} do { hintSilent "Beep"; sleep 1; }; Share this post Link to post Share on other sites
killzone_kid 1332 Posted January 19, 2019 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. 2 Share this post Link to post Share on other sites
Max2 0 Posted January 19, 2019 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
POLPOX 779 Posted January 19, 2019 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. 2 Share this post Link to post Share on other sites
pierremgi 4906 Posted January 19, 2019 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