wiggum2 31 Posted October 13, 2011 Hi ! I just played around with the "breakTo" command but even the most simple script does not work... private ["_x"]; scopeName "main"; _x = 0; while{true} do { _x = _x + 1; hint format["%1", _x]; sleep 1; if(_x == 5) then {breakTo "main"}; }; Now i got this from a "working" example Kegetys posted, but for me its not working. The script counts to five and then stops doing anything. I also tried many other things like making another scope or/and using breakOut...nothing works for me. I call the script from a trigger with condition true and: nul=execVM "whyohmygod.sqf" Is the command broken ? Share this post Link to post Share on other sites
.kju 3245 Posted October 13, 2011 No it works as it should be. The problem is that you have a wrong idea what it does. It is NOT goto. It exits to the current scope to the given scope. So in your example it will continue AFTER the while loop. Share this post Link to post Share on other sites
CarlGustaffa 4 Posted October 13, 2011 Untested, but... private ["_x"]; scopeName "main"; _x = 0; while{true} do { _x = _x + 1; hint format["%1", _x]; sleep 1; if(_x == 5) then {breakTo "main"}; hint "this should not show"; }; hint "this should show"; Does that work as I intended? Also, if you only have one variable, you don't need to use private statement with array, private "_x"; would be enough. And since you're already initializing it at the beginning, strictly speaking it is not needed. Share this post Link to post Share on other sites
wiggum2 31 Posted October 13, 2011 (edited) Ok, i got that...but the example on the BIKI sounds a bit differend: scopeName "main"; while {true} do { scopeName "loop1"; while {true} do { scopeName "loop2"; if (condition1) then {breakTo "main"}; // Breaks all scopes and return to "main" if (condition2) then {breakOut "loop2"}; // Breaks scope named "loop2" sleep 1; }; sleep 1; }; The Breaks all scopes and return to "main" part sounds like goto for me... And im still dont understand it really whats the differense between "breakTo" and "brekOut" is... And this dont works: private ["_x"]; _x = 0; scopeName "main"; while{true} do { scopeName "loop1"; while{true} do { _x = _x + 1; hint format["%1", _x]; sleep 1; if(_x == 5) then {breakTo "loop1"}; hint "NOOOOOOOOOOOO"; }; scopeName "loop2"; while{true} do { _x = _x - 1; hint format["%1", _x]; sleep 1; if(_x == 0) then {breakTo "loop2"}; hint "NOOOOOOOOOOOOOOOOOOOO"; }; }; hint "YEEEEEEEEEEEEEES"; I always get a error in line 15 (scopeName "loop2") And i never see the "Yes" hint. Edited October 13, 2011 by Wiggum Share this post Link to post Share on other sites
.kju 3245 Posted October 13, 2011 Do you use squint by Mac yet? Share this post Link to post Share on other sites
Master85 1 Posted October 13, 2011 I always get a error in line 15 (scopeName "loop2"). you're trying to name the same scope twice (loop1 and loop2) - that's not allowed. Share this post Link to post Share on other sites
wiggum2 31 Posted October 13, 2011 (edited) So, if breakTo is no "goto"...its basicly just something to break out of a while loop even if the actuall while condition is still true ? And could you explain/show me a situation where i would need "breakOut" please ? Do you use squint by Mac yet? Yes, it shows me no errors with this script. you're trying to name the same scope twice (loop1 and loop2) - that's not allowed. Sorry, could you show that to me with a example, i dont understand what you mean. Edited October 13, 2011 by Wiggum Share this post Link to post Share on other sites
st_dux 26 Posted October 13, 2011 The Breaks all scopes and return to "main" part sounds like goto for me... It goes back to the main scope; it does not go back to the line where you wrote the word "main"; that line is immaterial. Share this post Link to post Share on other sites
nuxil 2 Posted October 13, 2011 (edited) Also keep in mind if you use BreakOut on most inner scopename you will terminate the script. scopeName "main"; sleep 1; hint "Main scope"; _A=0; _B=0; if(true) then { //this is a scope so we name it scopeName "if"; //if (BREAK==0) then {_A=_A+1; breakTo "main";}; if (BREAK==0) then {_A=_A+1; breakOut "if";}; // same as above. but breaks out of "if" scope and continutes if (BREAK==1) then {_A=_A+1; breakOut "main";}; // terminates the script }; sleep 1; hint format["%1\n%2",_A,_B]; Edited October 13, 2011 by nuxil Share this post Link to post Share on other sites
wiggum2 31 Posted October 14, 2011 @ nuxil Thanks, i hope i got it now. Share this post Link to post Share on other sites
wiggum2 31 Posted October 22, 2011 Sorry, but i got a problem with this again: private ["_x"]; _x = 0; scopeName "main"; while{true} do { scopeName "loop1"; while{true} do { _x = _x + 1; hint format["%1", _x]; sleep 1; if(_x == 5) then {breakTo "loop1"}; hint "NOOOOOOOOOOOO"; }; scopeName "loop2"; while{true} do { _x = _x - 1; hint format["%1", _x]; sleep 1; if(_x == 0) then {breakTo "loop2"}; hint "NOOOOOOOOOOOOOOOOOOOO"; }; }; hint "YEEEEEEEEEEEEEES"; I always get a error in line 15 (scopeName "loop2"). Now master85 told me that: you're trying to name the same scope twice (loop1 and loop2) - that's not allowed. But why ? What did i do wrong ? Can someone show me what i have to change in my example to get it working without these error in line 15 ? Share this post Link to post Share on other sites
sickboy 13 Posted October 22, 2011 You can also use if (condition) exitWith { /* some code */ }; to exit the current scope only; http://community.bistudio.com/wiki/exitWith Share this post Link to post Share on other sites
wiggum2 31 Posted October 22, 2011 @ Sickboy Yes, thats a good idea too. But i would still like to know what is wrong with my example and why i "named the same scope twice" ? Share this post Link to post Share on other sites
buliwyf 4 Posted October 22, 2011 http://community.bistudio.com/wiki/scopeName ...and in your first While{}do{}-loop you use scopeName twice! private ["_x"]; _x = 0; while{true} do { scopeName "main"; while{true} do { scopeName "loop1"; _x = _x + 1; hint format["%1", _x]; sleep 1; if(_x > 4) then {breakOut "loop1"}; hint "NOOOOOOOOOOOO"; }; while{true} do { scopeName "loop2"; _x = _x - 1; hint format["%1", _x]; sleep 1; if(_x < 1) then {breakOut "loop2"}; hint "NOOOOOOOOOOOOOOOOOOOO"; }; breakOut "main"; }; hint "YEEEEEEEEEEEEEES"; Share this post Link to post Share on other sites
wiggum2 31 Posted October 22, 2011 Sorry, but look at the example from the BIKI: scopeName "main"; while {true} do { scopeName "loop1"; while {true} do { [...] So the "scopeName" always after the while or before ? Share this post Link to post Share on other sites
nuxil 2 Posted October 22, 2011 (edited) i think you missunderstand what scopes are. you might rather say. scope names is always after { but not entierly true scopename "a"; if (tralla) then { scopename "b"; if (something) then { scopename "c"; if (ok) then { code; }; // this is scope c }; //this is scope b }; //scope a i dont know if i can explain it better than this. you can not define a name for a scope twise in same scope. Edited October 22, 2011 by nuxil Share this post Link to post Share on other sites
wiggum2 31 Posted October 22, 2011 (edited) Ok, but what not works is this: scopename "a"; while {tralla} do { scopename "b"; while {something} do { code; }; //this is scope b scopename "c"; while {ok} do { code; }; // this is scope c }; //scope a But why ? I think a scope is jus everything after "scopeName" while/if {} Edited October 22, 2011 by Wiggum Share this post Link to post Share on other sites
buliwyf 4 Posted October 22, 2011 If you format your script you will see that you have two scopeName`s in one While-loop! private ["_x"]; _x = 0; scopeName "main"; [color="Red"]while{true} do {[/color] [color="Red"]scopeName "loop1";[/color] while{true} do { _x = _x + 1; hint format["%1", _x]; sleep 1; if(_x == 5) then {breakTo "loop1"}; hint "NOOOOOOOOOOOO"; }; [color="Red"]scopeName "loop2";[/color] while{true} do { _x = _x - 1; hint format["%1", _x]; sleep 1; if(_x == 0) then {breakTo "loop2"}; hint "NOOOOOOOOOOOOOOOOOOOO"; }; [color="Red"]};[/color] hint "YEEEEEEEEEEEEEES"; :coop: Share this post Link to post Share on other sites
wiggum2 31 Posted October 22, 2011 (edited) This looks like two sub-scopes inside one main-scope (while) to me: [color="Red"]scopeName "main"; while {true} do {[/color] [color="SeaGreen"]scopeName "loop1"; while {true} do { [/color] [color="Blue"]scopeName "loop2"; if (condition1) then { breakTo "main" }; if (condition2) then { breakOut "loop2" }; [/color] [color="SeaGreen"]}; [/color] [color="Red"]};[/color] @ Buliwyf I think you added the color a bit wrong. Again,why does it not work ? Why have (look a my example below) i named the same scope twice now ? Only one sub-scopename per while loop ? private ["_x"]; _x = 0; [color="Red"]scopeName "main"; while{true} do {[/color] [color="SeaGreen"]scopeName "loop1"; while{true} do {[/color] _x = _x + 1; hint format["%1", _x]; sleep 1; if(_x == 5) then {breakTo "loop1"}; hint "NOOOOOOOOOOOO"; [color="SeaGreen"]};[/color] [color="Blue"]scopeName "loop2"; while{true} do {[/color] _x = _x - 1; hint format["%1", _x]; sleep 1; if(_x == 0) then {breakTo "loop2"}; hint "NOOOOOOOOOOOOOOOOOOOO"; [color="Blue"]};[/color] [color="Red"]};[/color] hint "YEEEEEEEEEEEEEES"; It seems impossible to add more then one while sub-scopes to a main scope (while loop)... With a if scope this works, look at the example above. :rolleyes: Edited October 22, 2011 by Wiggum Share this post Link to post Share on other sites
nuxil 2 Posted October 22, 2011 .... It seems impossible to add more then one while sub-scopes to a main scope (while loop)... With a if scope this works, look at the example above. :rolleyes: not sure what you mean? but as i said. you can only name a scope once. scopename "a" while {true} do { scopename "b"; while {true} do { scopename "c"; while {true} do { scopename "d"; ... }; }; }; Share this post Link to post Share on other sites
wiggum2 31 Posted October 22, 2011 (edited) Yes, i understand. But look at my example, its just the same like you just posted isnt it ? private ["_x"]; _x = 0; [color="Red"]scopeName "main"; while{true} do {[/color] [color="SeaGreen"]scopeName "loop1"; while{true} do {[/color] _x = _x + 1; hint format["%1", _x]; sleep 1; if(_x == 5) then {breakTo "loop1"}; hint "NOOOOOOOOOOOO"; [color="SeaGreen"]};[/color] [color="Blue"]scopeName "loop2"; while{true} do {[/color] _x = _x - 1; hint format["%1", _x]; sleep 1; if(_x == 0) then {breakTo "loop2"}; hint "NOOOOOOOOOOOOOOOOOOOO"; [color="Blue"]};[/color] [color="Red"]};[/color] hint "YEEEEEEEEEEEEEES"; [color="Red"]scopename "a" while {true} do {[/color] [color="SeaGreen"] scopename "b"; while {true} do {[/color] [color="Blue"] scopename "c"; while {true} do {[/color] [color="Blue"]};[/color] [color="SeaGreen"]};[/color] [color="Red"]};[/color] Have you tried this ingame ? EDIT: Now i spotted my error..pretty clear now if i look at it ! But two seperate while loops (with scopeName) inside another while loop (main scope) should be possible i think... Edited October 22, 2011 by Wiggum Share this post Link to post Share on other sites
igneous01 19 Posted October 23, 2011 Yes, i understand.But look at my example, its just the same like you just posted isnt it ? private ["_x"]; _x = 0; [color="Red"]scopeName "main"; while{true} do {[/color] [color="SeaGreen"]scopeName "loop1"; while{true} do {[/color] _x = _x + 1; hint format["%1", _x]; sleep 1; if(_x == 5) then {breakTo "loop1"}; hint "NOOOOOOOOOOOO"; [color="SeaGreen"]};[/color] [color="Blue"]scopeName "loop2"; while{true} do {[/color] _x = _x - 1; hint format["%1", _x]; sleep 1; if(_x == 0) then {breakTo "loop2"}; hint "NOOOOOOOOOOOOOOOOOOOO"; [color="Blue"]};[/color] [color="Red"]};[/color] hint "YEEEEEEEEEEEEEES"; [color="Red"]scopename "a" while {true} do {[/color] [color="SeaGreen"] scopename "b"; while {true} do {[/color] [color="Blue"] scopename "c"; while {true} do {[/color] [color="Blue"]};[/color] [color="SeaGreen"]};[/color] [color="Red"]};[/color] Have you tried this ingame ? EDIT: Now i spotted my error..pretty clear now if i look at it ! But two seperate while loops (with scopeName) inside another while loop (main scope) should be possible i think... follow the closing of the brackets, that tells you where scopes begin and end, if your script is formatted, every new tab indicates a new scope, so that means, that two scopes within the same tab of space, is wrong, because its the same scope. which is why: while {true} do { scopename "one"; blah..... if (blah) then { }; scopename "two"; }; throws an error, because the inside of that while loop (scope 1) is trying to be renamed to a different scope, that would only work and not error, if you moved scopename two inside the if statement, as that is a new tab of space, and a new scope. Share this post Link to post Share on other sites