Difference between revisions of "Blitz:First Program"

From Amiga Coding
Jump to: navigation, search
m
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
A simple Blitz basic program is shown below.
 
A simple Blitz basic program is shown below.
  
<code>
+
<pre>
 
NPrint "Hello World!"
 
NPrint "Hello World!"
  
Line 8: Line 8:
  
 
End
 
End
</code>
+
</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 NPrint statement automatically adds a newline character to the end of the message which moves the cursor onto the next line.
+
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 MouseWait command waits for the user to click the mouse button before continuing.
Line 16: Line 16:
 
The End statement tells the compiler to exit the program here and tidy up any resources that were used.
 
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.
+
 
 +
'''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:
 
A better option might be to replace the MouseWait command with these lines:
  
<code>
+
<pre>
 
NPrint "Press Enter to continue"
 
NPrint "Press Enter to continue"
  
dummy$ = Edit$(1)
+
dummy$ = Edit$(1)</pre>
</code>
+
 
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.
+
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]]
 
[[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.