Stop: Difference between revisions
imported>Felice Enellen (Undo revision 962 by Felice Enellen (talk) (oops, wrong edit box)) |
imported>Felice Enellen (document arguments to stop()) |
||
| Line 1: | Line 1: | ||
{{ApiReference | {{ApiReference | ||
|name=stop | |name=stop | ||
|message|optional|An optional message to print before stopping. | |||
|x|optional|The x coordinate of the upper left corner to start printing. | |||
|y|optional|The y coordinate of the upper left corner to start printing. | |||
|col|optional|The color to use for the text. | |||
|shortdesc=Stops the program's execution and returns to the [[CommandPrompt|command prompt]]. | |shortdesc=Stops the program's execution and returns to the [[CommandPrompt|command prompt]]. | ||
}} | }} | ||
{{UndocumentedFeature}} | {{UndocumentedFeature}} | ||
The <code>stop()</code> function stops the program at the point where the function is called, returning to the [[CommandPrompt|command prompt]]. This is similar to pressing the Escape key at a specific point in the code. | The <code>stop()</code> function stops the program at the point where the function is called, returning to the [[CommandPrompt|command prompt]]. This is similar to pressing the Escape key at a specific point in the code. | ||
Note that the format of the optional arguments is identical to the more-familiar [[Print|print()]]. This can be useful for explaining why the app has exited, especially if combined with information from [[Trace|trace()]]. | |||
If your program uses the [[GameLoop|game loop]], you can resume execution of the program using the [[Resume|resume]] command. This does ''not'' resume from the call to <code>stop()</code>. Instead, it starts the next loop iteration with a call to [[Update|_update()]]. If your program does not use the game loop, [[Resume|resume]] raises an error. | If your program uses the [[GameLoop|game loop]], you can resume execution of the program using the [[Resume|resume]] command. This does ''not'' resume from the call to <code>stop()</code>. Instead, it starts the next loop iteration with a call to [[Update|_update()]]. If your program does not use the game loop, [[Resume|resume]] raises an error. | ||
Revision as of 20:08, 22 January 2018
- Stops the program's execution and returns to the command prompt.
- message
-
- An optional message to print before stopping.
- x
-
- The x coordinate of the upper left corner to start printing.
- y
-
- The y coordinate of the upper left corner to start printing.
- col
-
- The color to use for the text.
The stop() function stops the program at the point where the function is called, returning to the command prompt. This is similar to pressing the Escape key at a specific point in the code.
Note that the format of the optional arguments is identical to the more-familiar print(). This can be useful for explaining why the app has exited, especially if combined with information from trace().
If your program uses the game loop, you can resume execution of the program using the resume command. This does not resume from the call to stop(). Instead, it starts the next loop iteration with a call to _update(). If your program does not use the game loop, resume raises an error.
Examples
v = 1 function _update() v += 1 if (v % 5) == 0 then stop() end end function _draw() cls() print(v, 0, 0, 8) end
Running this program stops when v is a multiple of 5. From the command prompt:
> print(v) 5 > resume
The program stops again at the next multiple of 5:
> print(v) 10