Crash Course to Hollywood Programming

From MorphOS Library

Revision as of 11:47, 28 October 2017 by JPV (talk | contribs)

Author: jPV/RNO (Proofreading by Marq)

Preface

Hollywood - the cross-platform multimedia application layer - is an easy programming/scripting language that is designed for the creation of graphical or multimedia-oriented applications, but it can also be used to create other kinds of programs, especially with its comprehensive selection of plugins. Hollywood is loosely based on the popular Lua language.

Hollywood programs are created by writing script files, which are then run from the Hollywood main program, or they can be compiled into applets or standalone executables to be used without the Hollywood environment.

Applets are small platform-independent binary files which can be run using the free Hollywood player on any supported platform. Standalone executables contain the player, a script and optional data files linked into a single executable file. Linking the whole player binary into an executable makes the minimum size of Hollywood executables around 2 megabytes on MorphOS, but then the resulting programs are completely independent and can be run out of the box without any prior installation.

What makes Hollywood special is its ability to cross-compile programs between all supported platforms. Windows, Linux, OS X, or Amiga programs can be compiled just by using MorphOS, and so on. Cross-compiled programs don't usually need any modifications and the same source script will work on all platforms.

Hollywood is an easy, safe, and very well documented language, and thus also suitable for beginners. All Hollywood programs run inside a sandbox, and you can't break or crash the underlying operating system with your programming mistakes. If there's a bug causing an error in the script execution, Hollywood just closes the program and frees the resources with no further harm.


Getting Started

Requirements

Hollywood

Hollywood is a commercial product which can be bought here. The main package is enough for Hollywood programming and compiling for all other platforms except Android (Windows-only APK Compiler is required for the Android support).

Hollywood Designer is an Amiga-only add-on to create multimedia presentations in a WYSIWYG GUI. It works on Amiga compatible platforms including MorphOS, but the resulting presentations can be compiled for any other supported platform. Anyway, it isn't required for programming with Hollywood, but your own code can be inserted into presentation scripts too.


Text Editor

Hollywood features an IDE (integrated development environment) for Windows, but on other platforms a text editor or a 3rd party IDE is needed.

Cubic IDE offers the best development environment for Hollywood programming on MorphOS. With the Cubic IDE add-on you'll get syntax highlighting, automatic casing, online help, quick access to documentation, automatic indentation, bracket matching, auto completion of keywords, compile and run options, and a lot more.

MiniHollyEdit NG could also be a good freeware option, but it's broken in its current state and needs an update first.

An IDE with Hollywood support is the most comfortable solution of course, but any other text editor will also do.


Running a Script

Hollywood scripts can be run from the Hollywood main executable (the interpreter), and while the main executable accepts tens of command line arguments, you don't usually need many of them.

When you're developing and testing your application, it's enough to just run the script without compiling it. It's a good practise to save your scripts with the .hws extension.


To run a script from the shell:

Hollywood MyProgram.hws


And without the information window:

Hollywood MyProgram.hws -quiet


Hollywood has a built-in resource monitor, which can be activated with the -resourcemonitor argument. You should check the resources your application uses and that you aren't increasing the memory usage carelessly:

Hollywood MyProgram.hws -resourcemonitor


If you're using Cubic IDE, you don't need the shell at all. You can just press the F4 key to run the script or select other running options from Cubic IDE's menus.


Compiling a Script

When an application is ready for publishing, it should be compiled into a standalone executable, which is done with the -compile argument:

Hollywood MyProgram.hws -compile MyProgram

With the above command you get an executable called "MyProgram" that will run on the same archtecture it was compiled on.


To compile an application for different platforms (OS4 in this example):

Hollywood MyProgram.hws -compile MyProgram -exetype amigaos4


Or for multiple platforms at once:

Hollywood MyProgram.hws -compile MyProgram.exe -exetype morphos|amigaos4|win32|applet


If you want to compress your own data (script and linked data files), add the -compress argument:

Hollywood MyProgram.hws -compile MyProgram.exe -exetype morphos|amigaos4|win32|applet -compress

Compressing can make executables smaller, but it also "hides" any plaintext data from the executables if you prefer that.


Compiling in Cubic IDE is simply done by pressing the F2 key or by selecting the platform for cross-compiling from the menus.


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.


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.