Difference between revisions of "Crash Course to Hollywood Programming/Example 1 - The First Test"

From MorphOS Library

< Crash Course to Hollywood Programming

 
Line 2: Line 2:
  
 
Let's type this into a text editor and save it as a file called '''RAM:firsttest.hws''':
 
Let's type this into a text editor and save it as a file called '''RAM:firsttest.hws''':
  [http://www.hollywood-mal.com/docs/html/hollywood/atBGPIC.html @BGPIC] 1, "SYS:MorphOS/Prefs/Wallpapers/1024x768/Arida.png"
+
  [http://www.hollywood-mal.com/docs/html/hollywood/atBGPIC_.html @BGPIC] 1, "SYS:MorphOS/Prefs/Wallpapers/1024x768/Arida.png"
  [http://www.hollywood-mal.com/docs/html/hollywood/TextOut.html TextOut](100,10,"Hello World!")
+
  [http://www.hollywood-mal.com/docs/html/hollywood/TextOut_.html TextOut](100,10,"Hello World!")
  [http://www.hollywood-mal.com/docs/html/hollywood/WaitLeftMouse.html WaitLeftMouse]()  
+
  [http://www.hollywood-mal.com/docs/html/hollywood/WaitLeftMouse_.html WaitLeftMouse]()  
  ; Program exits after the last line in a script, but you can also terminate it with the [http://www.hollywood-mal.com/docs/html/hollywood/End.html End]() command
+
  ; Program exits after the last line in a script, but you can also terminate it with the [http://www.hollywood-mal.com/docs/html/hollywood/End_.html End]() command
  
The first line is a [http://www.hollywood-mal.com/docs/html/hollywood/PrgPreproc.html preprocessor command] which loads the given image file as a Hollywood background
+
The first line is a [http://www.hollywood-mal.com/docs/html/hollywood/PrgPreproc_.html preprocessor command] which loads the given image file as a Hollywood background
 
picture. Objects in Hollywood are handled by their '''ID numbers''', and in this case we load the image as
 
picture. Objects in Hollywood are handled by their '''ID numbers''', and in this case we load the image as
 
a bgpic number 1. That bgpic is also loaded initially when the application opens its window.
 
a bgpic number 1. That bgpic is also loaded initially when the application opens its window.
Line 20: Line 20:
 
and close its window, and we wouldn't see much.
 
and close its window, and we wouldn't see much.
  
The last line is a [http://www.hollywood-mal.com/docs/html/hollywood/PrgComments.html comment] line, which is just a note inside the code. Comment lines can be inserted between
+
The last line is a [http://www.hollywood-mal.com/docs/html/hollywood/PrgComments_.html comment] line, which is just a note inside the code. Comment lines can be inserted between
 
'''/*''' and '''*/''', or the rest of the line can be commented out with the ''';''' character.  
 
'''/*''' and '''*/''', or the rest of the line can be commented out with the ''';''' character.  
  
Line 30: Line 30:
 
Hollywood opens a new window and takes its dimensions from the background picture. If we wouldn't preload any
 
Hollywood opens a new window and takes its dimensions from the background picture. If we wouldn't preload any
 
background picture, then the display would be opened in the default 640x480 resolution, or you could define
 
background picture, then the display would be opened in the default 640x480 resolution, or you could define
its dimensions with the [http://www.hollywood-mal.com/docs/html/hollywood/atDISPLAY.html @DISPLAY] preprocessor command.
+
its dimensions with the [http://www.hollywood-mal.com/docs/html/hollywood/atDISPLAY_.html @DISPLAY] preprocessor command.
  
  

Latest revision as of 17:05, 2 November 2017

First Test

Let's type this into a text editor and save it as a file called RAM:firsttest.hws:

@BGPIC 1, "SYS:MorphOS/Prefs/Wallpapers/1024x768/Arida.png"
TextOut(100,10,"Hello World!")
WaitLeftMouse() 
; Program exits after the last line in a script, but you can also terminate it with the End() command

The first line is a preprocessor command which loads the given image file as a Hollywood background picture. Objects in Hollywood are handled by their ID numbers, and in this case we load the image as a bgpic number 1. That bgpic is also loaded initially when the application opens its window.

All preprocessor commands are prefixed with the @ character and processed before the actual script execution. Data files loaded with the preprocessor commands are also linked into the executable when compiling a program. If you don't want to link the files, you can load them separately later in the script.

The second line prints the "Hello World!" text at x=100, y=10 (in pixels) over the background image.

The third line waits for the user to press the left mouse button. Without this line, the program would just end and close its window, and we wouldn't see much.

The last line is a comment line, which is just a note inside the code. Comment lines can be inserted between /* and */, or the rest of the line can be commented out with the ; character.


firsttest.hws running

Let's run the script to see the results. Hit the F4 key in Cubic IDE or type this in the shell:

Hollywood RAM:firsttest.hws -quiet

Hollywood opens a new window and takes its dimensions from the background picture. If we wouldn't preload any background picture, then the display would be opened in the default 640x480 resolution, or you could define its dimensions with the @DISPLAY preprocessor command.


Next let's compile the program into a standalone executable. Hit the F2 key in Cubic IDE or use the shell (you don't have to define the paths if you've already changed directory to RAM: in the shell):

Hollywood RAM:firsttest.hws -compile RAM:firsttest

Now we have a new executable file that also contains the preprocessed/linked background graphics in it. The program works even if you don't have the Arida.png file in the system.


> Proceed to the next example