Print will display a string or value to the screen. You'll notice the command doesn't require a position, this is because the text is drawn at the current text cursor position.
The cursors default position is the top left hand corner of the screen. Each time something is printed, the cursor will automatically step down to the next line for you. Allowing you to display information with having to manually set the position where each piece of text should be displayed. FACTS:
* Print can display Integer, Float & String information.
* Information displayed using Print, will be drawn at the current Text Cursor position. (See GetCursorX & GetCursorY)
* Print will display any information using the current FONT. See GetCurrentFont
* Printing off the bounds of the screen height, unlike some old editions of Basic will NOT scroll the screen automatically.
* Print renders to the current surface, except when the user either CaptureToScene, or CaptureToWorld are activated. In either situation, the draw request will be add to the scene or world queues.
Mini Tutorial:
This simple example, displays two messages to the screen.
; Display the first message Print "Hello World" ; Display the first message Print "This is My First PlayBASIC Program" ; Display the Screen and wait for the user to press a key Sync WaitKey |
This example would output. Hello World This is My First PlayBASIC Program |
Mini Tutorial:
This example shows that we can not only display string messages, but we can Print variables and the results of calculations too.
; Declare the integer variable SCORE ;and assign it a value of 500 Score=500 ; Declare the float variable Friction# ;and assign it a value of 22.456 Friction#=22.456 ; Declare the string variable ProgramName$ ;and assign it the string "PlayBasic" ProgramName$="PlayBasic" ; Display the message Print "Print Can Display Variables" ; Display the contents of the Score Variable Print Score ; Display the contents of the Friction Variable Print Friction# ; Display the contents of the ProgramName$ Variable Print ProgramName$ ; Display a blank line Print "" ; Display the message Print "Print Can Display Results of Calculations" ; Display the contents of the Score Variable * 10 Print Score*10 ; Display the contents of the Friction Variable * 10 Print Friction# * 10 ; Display the contents of the ProgramName$ + " Is Fun" Print ProgramName$+" Is Fun!" ; Display the Screen and wait for the user to press a key Sync WaitKey |
This example would output. Print Can Display Variables 500 22.456 PlayBasic Print Can Display Results of Calculations 5000 224.56 PlayBasic Is Fun! |
Mini Tutorial:
This example demonstrates how we can print combinations of Integer /Float and string Variables together, using String Addition and the Str$() / Digits$() functions.
; Declare the integer variable SCORE ; and assign it a value of 500 Score=500 ; Display the message Print "Combining Strings And Values" ; Since Print can only display one item at a time, if we ; wish to combine items, such a string and integer/float ; together, then we'll need to convert any values into ; strings and append (Add) them together for output. ; So here we'll display the String message "Score:" ; combined with Integer Variable Score. ; Do to this, we'll use the STR$() function to convert the ; variable Score into a temp string. This temp string is ; then added the "Score:" creating the resulting "Score:500" ; string, for Print to display. ; Display the "Score:" message Print "Score:" + Str$(Score) ; Embed the Score into a sentence Print "You only scored " + Str$(Score)+" that time!" ; Display empty string (inserts a blank line) Print "" ; Display message Print "Formatted Printing" ; Display the score message and score formated ; to 6 digits Print "Score:" + Digits$(Score,6) ; Embed the Score into a sentence Print "You only scored " + Digits$(Score,6)+" that time!" ; Display the Screen and wait for the user to press a key Sync WaitKey |
This example would output. Combining Strings And Values Score:500 You only scored 500 that time! Formatted printing Score:000500 You only scored 000500 that time! |
|