inofix 10 Posted February 23, 2015 Hello, i'm currently struggling with the following: I have a while loop running and i need to continue/start from beginning at some point. Sadly i can't find any "continue" command in sqf, neither does Goto work and scopeName + breakOut/To. Is there any way i can continue my loop (like in C/C++) or start the loop again from the beginning without reloading the script? Share this post Link to post Share on other sites
jshock 513 Posted February 23, 2015 Could you provide a bit more on what exactly your trying to accomplish, and maybe provide the code you have currently. Share this post Link to post Share on other sites
inofix 10 Posted February 23, 2015 Example: while{true} do { _result = [] call fnc_IsAtBase; if(!_result) exitWith { }; if(_damage > 0) then { vehicle player setDamage (_damage - 0.1); _damage = damage vehicle player; Continue; // Continue loop from beginning again }; if(_fuel < 1) then { vehicle player setFuel (_fuel + 0.1); __fuel = fuel vehicle player; Continue; // Continue loop from beginning again }; // And more threads for ammo, color, and custom scripts }; Share this post Link to post Share on other sites
jshock 513 Posted February 23, 2015 As soon as an if statement's code scope is completed it continues, you don't have to do anything. But you will need to put some sort of suspension to slow the loop down or it will freeze the game (has the possibility at least). Share this post Link to post Share on other sites
inofix 10 Posted February 23, 2015 That's not what i need. I want after the completed if statement continues to start the loop again from the beginning, simlar to the this here: http://www.tutorialspoint.com/cplusplus/cpp_continue_statement.htm Share this post Link to post Share on other sites
jshock 513 Posted February 23, 2015 (edited) Ok, get you now, just do this for each of your conditions: if([] call fnc_IsAtBase && {_damage > 0}) then {...}; EDIT: Or, while {true} do { if ([] call fnc_IsAtBase) then { _fixStuff = [_unit] spawn { _unit = (_this select 0); if(_damage > 0) then { vehicle player setDamage (_damage - 0.1); _damage = damage vehicle player; }; if(_fuel < 1) then { vehicle player setFuel (_fuel + 0.1); _fuel = fuel vehicle player; }; }; waitUntil {scriptDone _fixStuff}; }; sleep 10; }; Edited February 23, 2015 by JShock Share this post Link to post Share on other sites
fight9 14 Posted February 23, 2015 (edited) I may be confused about what you want... but this may be it. [color="#FF8040"][color="#191970"][b]while[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#000000"]true[/color][color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#1874CD"]_result[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] fnc_IsAtBase[color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]if[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]![/b][/color][color="#1874CD"]_result[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]if[/b][/color] [color="#000000"]true[/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#006400"][i]// for the scope[/i][/color] [color="#1874CD"]_damage[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]damage[/b][/color] [color="#191970"][b]vehicle[/b][/color] [color="#000000"]player[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]if[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_damage[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#006400"][i]// exit scope with action[/i][/color] [color="#191970"][b]vehicle[/b][/color] [color="#000000"]player[/color] [color="#191970"][b]setDamage[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_damage[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]0.1[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]_fuel[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]fuel[/b][/color] [color="#191970"][b]vehicle[/b][/color] [color="#000000"]player[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]if[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_fuel[/color] [color="#8B3E2F"][b]<[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#006400"][i]// exit scope with action[/i][/color] [color="#191970"][b]vehicle[/b][/color] [color="#000000"]player[/color] [color="#191970"][b]setFuel[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_fuel[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#FF0000"]0.1[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// And more threads for ammo, color, and custom scripts[/i][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// slow down loop[/i][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color] Made with KK's SQF to BBCode Converter EDIT: _damage & _fuel need to be defined before their if statements. Edited February 23, 2015 by Fight9 Share this post Link to post Share on other sites
jshock 513 Posted February 23, 2015 EDIT: _damage & _fuel need to be defined before their if statements. Yea I think he gave us semi-pseudo code, just to get a concept of what needs to happen with it. Share this post Link to post Share on other sites
killzone_kid 1332 Posted February 24, 2015 To use goto you need to write your script in .sqs and execute it with "exec" command. There are plenty of alternatives of course: [color="#FF8040"][color="#191970"][b]while[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] fnc_IsAtBase[color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#191970"][b]switch[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]true[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#191970"][b]case[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_damage[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]:[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#191970"][b]vehicle[/b][/color] [color="#000000"]player[/color] [color="#191970"][b]setDamage[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_damage[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]0.1[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]_damage[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]damage[/b][/color] [color="#191970"][b]vehicle[/b][/color] [color="#000000"]player[/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]case[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_fuel[/color] [color="#8B3E2F"][b]<[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]:[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#191970"][b]vehicle[/b][/color] [color="#000000"]player[/color] [color="#191970"][b]setFuel[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_fuel[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#FF0000"]0.1[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]__fuel[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]fuel[/b][/color] [color="#191970"][b]vehicle[/b][/color] [color="#000000"]player[/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]default[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// And more threads for ammo, color, and custom scripts[/i][/color] [color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]//<-- you dont really want immediate repeat[/i][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color] Made with KK's SQF to BBCode Converter Share this post Link to post Share on other sites
dreadedentity 278 Posted February 24, 2015 (edited) num = 0; scopeName "main"; while {true} do { scopeName "outerLoop"; while {true} do { num = num + 1; hintSilent str num; if (num == 2) then { systemChat "WTF"; breakTo "outerLoop"; }; if (num == 4) then { breakTo "main"; }; sleep 1; }; sleep 1; }; hint "Done"; scopeName, breakTo But this is a terrible idea. There's a reason structured programming is specifically called "goto-less programming" Edited February 24, 2015 by DreadedEntity Share this post Link to post Share on other sites
Ed! 13 Posted February 24, 2015 what if you avoid a loop and do something like this. [u]functionName[/u] = { _result = [] call fnc_IsAtBase; if(!_result) exitWith { }; if(_damage > 0) exitWith{ vehicle player setDamage (_damage - 0.1); _damage = damage vehicle player; [] spawn [u]functionName[/u]; //or call if you like }; if(_fuel < 1) exitWith{ vehicle player setFuel (_fuel + 0.1); __fuel = fuel vehicle player; [] spawn [u]functionName[/u]; //or call if you like }; // And more threads for ammo, color, and custom scripts }; [] spawn [u]functionName[/u]; Share this post Link to post Share on other sites