{"name":"goto","title":"goto","type":"command","url":"https://community.bistudio.com/wiki/goto","revid":364521,"updated":"2024-05-16T20:46:23Z","groups":["Program Flow"],"status":"ok","games":{"ofp":"1.00","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.00","arma3_since":"0.50","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","params":[{"name":"label","type":"String","type_expr":"String"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"unary","right":{"text":"label"}}],"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!\""]}],"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\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```"}]}