goto: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
(Somewhat improved formatting and clarified.)
Line 28: Line 28:
'''Example:'''
'''Example:'''


'''''goto''' "Skip"''<br>
'''''goto''' "Skip"''
. ''these lines''<br>
  ''these lines''
. ''will be''<br>
  ''will be''
. ''skipped''<br>
  ''skipped''
''#Skip
''#Skip






'''Comments:'''
'''Comments:'''
* This function works only inside of [[Script syntax|SQS script]].


*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.
*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.


Furthermore, loops which are executed often, should be placed at the top of a script.
* Because of the searching order, it is faster to place loops which are executed often at the top of a script.
 
*Labels are not case sensitive.


*Loops which look something like the example below should be avoided as many of them could cause the mission to slow down:
* Labels are not case sensitive.


* Loops which look something like the example below should be avoided as many of them could cause the mission to slow down:


''#wait''


''[[if]] (condition) [[then]] {'''goto''' "wait"}''
''#wait''
''[[if]] (condition) [[then]] {'''goto''' "wait"}''





Revision as of 16:28, 24 July 2006


goto label


Operand types:

label: String

Type of returned value:

Nothing

Description:

In script only: Go to given label.
Note: String argument is used here.
Be sure to use double quotes around label name in goto.

Define the label with #.


Example:

goto "Skip"
 these lines
 will be
 skipped
#Skip


Comments:

  • 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.
  • Because of the searching order, it is faster to place loops which are executed often at the top of a script.
  • Labels are not case sensitive.
  • Loops which look something like the example below should be avoided as many of them could cause the mission to slow down:


#wait
if (condition) then {goto "wait"}


It is better to use the @ command to wait for a condition to be true, or put a small delay into the wait loop.


Example

  • 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.

Unless you really want the loop to execute multiple times during a frame, you should include a small delay.

You would need to have many scripts running for this to be a significant issue.

  • 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.