{"name":"goto","operator":null,"title":"goto","type":"command","url":"https://community.bistudio.com/wiki/goto","revid":364521,"updated":"2024-05-16T20:46:23Z","groups":["Program Flow"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Break script flow and go to given label (defined by **#** - **NOT** to be confused with SQF's hash sign!)\n\n> [!WARNING]\n> This command only works in SQS Syntax.\n\n> [!NOTE]\n> Note that labels are not case sensitive and are searched for from the top of the script, so multiple occurrences of a label will only result in the topmost one ever being found.","syntaxes":[{"syntax":"goto label","since":null,"effect":null,"exec":null,"params":[{"name":"label","type":"String","optional":false,"default":null,"description":null,"types":["String"],"since":null,"text":"label: String"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"unary","operator":null,"left":null,"right":{"text":"label","types":["String"]}}],"examples":[{"text":"```sqs\ngoto \"myLabel\"\nplayer setDamage 1\n\n#myLabel\nhint \"you successfully avoided death!\"\n```","code":["goto \"myLabel\"\nplayer setDamage 1\n\n#myLabel\nhint \"you successfully avoided death!\""]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["Control Structures","SQS to SQF conversion"],"notes":[{"user":"Hardrock","date":"2006-08-04T10:52:00Z","text":"*Notes from before the conversion:*\n\n- This function works only inside of SQS script.\n- The search for labels always begins at the top of the script so that if there are multiple occurrences of a label the first occurrence will always be the one found.\n- Because of the searching order, it is faster to place loops which are executed often at the top of a script.\n- Labels are not case sensitive.\n- Loops which look something like the example below should be avoided as many of them could cause the mission to slow down:\n\n```sqs\n#wait\nif (condition) then { goto \"wait\" }\n```\n\nIt is better to use the **@** command to wait for a condition to be true, or put a small delay into the wait loop.\n\nExample:\n- While it is not required to include a delay in a loop, such a loop without a delay can cause the script to slow the game down, as the loop will be executed many times before the game engine interrupts the script.\n- Unless you really want the loop to execute multiple times during a frame, you should include a small delay.\n- You would need to have many scripts running for this to be a significant issue.\n- Deciding whether to use a script with a loop or a trigger or even a **@** statement to detect a condition is a complicated matter and should be subject to experimentation."},{"user":"UNN","date":"2006-08-04T12:17:00Z","text":"A goto command called within a forEach loop will only execute a single jump to goto, once the forEach loop has finished:\n\n```sqs\n{ goto \"wait\" } forEach [0, 1, 2, 3, 4]\n```"}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Program Flow","Introduced with Operation Flashpoint version 1.00","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}