7.1 Your first Hollywood program

Hollywood's script language is easy to use but very powerful! The syntax is based mainly on BASIC but Hollywood is much more powerful because it is a dynamically typed language! We will figure out later what this means for the programmer. Hollywood incorporates the best elements of (Blitz-) BASIC, C, AmigaE, Pascal and Lua into one powerful, flexible language that allows you to do almost everything with little effort.

Hollywood scripts are just plain text files in UTF-8 encoding. So fire up your favorite text editor now and start creating your first script!

This is how the famous 'Hello World' program looks in Hollywood:

 
Print("Hello World!")
WaitLeftMouse()
End()

The little program above will open a 640x480 display. If you want Hollywood to open a display with other dimensions, you will need to use the @DISPLAY or the @BGPIC preprocessor command. 640x480 is the default display size that Hollywood uses when you do not specify anything else. The display size is not the same as the screen size. It is just the size of your display (your work area!). The screen size can be anything which is large enough to hold the display. Your display will be centered on the screen (you can use the @DISPLAY preprocessor command if you want a different initial display position). The window that is opened and holds the display will be larger than your display size if it has borders. If you specify the -borderless argument the window's size will match your display size.

If you want to have a fancy background picture instead of a plain black background, just place the @BGPIC preprocessor command at the beginning of your script:

 
@BGPIC 1, "FancyBackground.jpg"
Print("Hello World!")
WaitLeftMouse()
End()

You can also place multiple commands in one line, so the above code could also be written like this:

 
Print("Hello World!") WaitLeftMouse() End()

However, it is advised to use line feeds to make your code better readable. To achieve this, you can also use comments starting with a /* and ending with a */ or just a single line comment starting with ;, e.g.:

 
/* this is a comment */
Print("Hello World!")   ; this one too
WaitLeftMouse()   ; Wait for left mouse
End()  ; Exit

If a Hollywood function does neither accept nor return any arguments, you can leave out the parentheses when you call the function. If you pass arguments to a function however or if you want to store the return value of a function, you have to use parentheses. In our example, we could leave out the parentheses for the WaitLeftMouse() and End() commands because they do not take any arguments:

 
Print("Hello World!")
WaitLeftMouse
End

Of course, it is also possible to use variables instead of direct numbers or strings. You do not need to declare variables, they will be initialized to zero or an empty string respectively when you first use them. Variables have to start with a letter from A/a to Z/z or with an underscore. After that, they can also contain the numbers from 0 to 9, the dollar sign ($) and the exclamation mark (!). As a matter of style, variables that hold strings should have a dollar sign as their last character and variables that hold floating point values should have an exclamation mark as the last character. This makes your code better readable. The length of a variable name must not exceed 64 characters.

 
mystring$ = "Hello World!"
Print(mystring$)
WaitLeftMouse
End

Besides normal commands, there are also preprocessor commands available in Hollywood. These commands are processed before the script execution starts and they are always prefixed with an @-character (at). One of those preprocessor commands is @VERSION. It allows you to define the version of Hollywood that the script requires as a minimum. For example, the following script will only work with Hollywood 2.0 and higher:

 
@VERSION 2,0
Print("Hello World!")
WaitLeftMouse
End

You should always use this preprocessor command as the first action of your script to make sure the version is checked before anything else.

If you type the code above in your text editor and save it as MyScript.hws, you can then start it from a console by typing:

 
Hollywood MyScript.hws [ARGUMENTS]

[ARGUMENTS] can be any combination of console arguments supported by Hollywood. See Console arguments for more information on supported arguments.

If you want to start your script through the GUI, start the GUI, click on "Display" and choose your script.

Congratulations, you have just created your first Hollywood script!


Show TOC