Difference between revisions of "Blitz:First Program"
m (Daedalus moved page First Program to Blitz:First Program: Categorise properly) |
m |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | ||
+ | A simple Blitz basic program is shown below. | ||
+ | |||
+ | <pre> | ||
+ | NPrint "Hello World!" | ||
MouseWait | MouseWait | ||
End | End | ||
+ | </pre> | ||
+ | |||
+ | This program will print the message "Hello World!" without quotes to the default output destination. In most cases this will be the Shell window. The [[Blitz:Shell Input/Output#NPrint|NPrint]] statement automatically adds a newline character to the end of the message which moves the cursor onto the next line. | ||
+ | |||
+ | The MouseWait command waits for the user to click the mouse button before continuing. | ||
+ | |||
+ | The End statement tells the compiler to exit the program here and tidy up any resources that were used. | ||
+ | |||
+ | |||
+ | '''Note:''' The MouseWait command should only be used in certain circumstances, e.g. debugging. This is because it accesses the hardware directly, and so will not work on next generation operating systems like AmigaOS4 and MorphOS. Also, it uses a "busy loop" which uses a lot of CPU time while it waits for the user to click. | ||
+ | |||
+ | A better option might be to replace the MouseWait command with these lines: | ||
+ | |||
+ | <pre> | ||
+ | NPrint "Press Enter to continue" | ||
+ | |||
+ | dummy$ = Edit$(1)</pre> | ||
+ | |||
+ | This version will print the message shown and then wait for the user to press Enter (or Return). The program will sleep while it waits so no CPU time is taken unnecessarily, and it will work with all variations of AmigaOS and derivatives. [[Blitz:Shell Input/Output#Edit.24|Edit$(1)]] waits for up to 1 character to be entered from the Shell. | ||
+ | |||
+ | [[Category:Blitz Basic / AmiBlitz|Blitz]] |
Latest revision as of 12:41, 25 January 2018
A simple Blitz basic program is shown below.
NPrint "Hello World!" MouseWait End
This program will print the message "Hello World!" without quotes to the default output destination. In most cases this will be the Shell window. The NPrint statement automatically adds a newline character to the end of the message which moves the cursor onto the next line.
The MouseWait command waits for the user to click the mouse button before continuing.
The End statement tells the compiler to exit the program here and tidy up any resources that were used.
Note: The MouseWait command should only be used in certain circumstances, e.g. debugging. This is because it accesses the hardware directly, and so will not work on next generation operating systems like AmigaOS4 and MorphOS. Also, it uses a "busy loop" which uses a lot of CPU time while it waits for the user to click.
A better option might be to replace the MouseWait command with these lines:
NPrint "Press Enter to continue" dummy$ = Edit$(1)
This version will print the message shown and then wait for the user to press Enter (or Return). The program will sleep while it waits so no CPU time is taken unnecessarily, and it will work with all variations of AmigaOS and derivatives. Edit$(1) waits for up to 1 character to be entered from the Shell.