IF -- test for condition (V7.0)
@IF val
This preprocessor command tests for the condition specified in val. If it is True, the preprocessor will continue parsing your script. If val is False, however, @IF will branch to the next @ELSEIF, @ELSE, or @ENDIF statement, allowing you to skip certain portions of the script if certain conditions aren't met.

Note that the condition must be a constant expression since @IF operates at preprocessor level, i.e. script variables are not available at that time. You can use numeric constants or Hollywood constants defined using either the Const statement or the -setconstants console argument. There are also some inbuilt constants that allow you to test for the platform Hollywood is running on (or compiling for) and the Hollywood version. Please see below for a list.

Also note that the @IF and @ELSEIF preprocessor commands won't complain if you use a constant that hasn't been declared at all. You won't get a "Constant not found!" error in this case. Instead, undeclared constants will simply evaluate to 0. The reason behind this design is that the platform-specific constants (see below) are only defined when running a Hollywood script on the respective platform or compiling for it. Thus, when testing for a certain platform on another platform, you won't get an error if the platform constant hasn't been defined. Instead, the non-existing constant will simply evaluate to 0.

In contrast to the normal If statement, @IF operates at preprocessor level. This means that you can use it to force the preprocessor to take certain routes or ignore certain portions of your code. This isn't possible with the normal If statement at all because once that executes, the preprocessor has already finished its job.

For example, you could force the preprocessor to parse different code depending on which platform Hollywood is running. You can also tell the preprocessor to ignore certain portions of the code. Those portions aren't even checked for syntactical correctness. They are completely skipped, just like comments, so anything could be in those blocks.

Here is an example which uses a different background picture and window title for the individual platforms supported by Hollywood:

   @BGPIC 1, "bg_amiga.png"
   @DISPLAY {Title = "My project (Amiga)"}
   @BGPIC 1, "bg_macos.png"
   @DISPLAY {Title = "My project (macOS)"}
   @BGPIC 1, "bg_linux.png"
   @DISPLAY {Title = "My project (Linux)"}
   @BGPIC 1, "bg_windows.png"
   @DISPLAY {Title = "My project (Windows)"}
   @BGPIC 1, "bg_default.png"
   @DISPLAY {Title = "My project (Default)"}

You wouldn't be able to use the normal If statement for this purpose because, as its very name implies, the preprocessor parses the script before it is run. Hence, if you used the normal If statement all preprocessor commands in the code above would be parsed and executed because the preprocessor command would just ignore runtime instructions like the normal If statement.

As you can see above, there are some inbuilt constants that allow you to test for the platform Hollywood is currently running or compiling for. The following inbuilt constants are available:

Defined on AmigaOS or compatible platforms, i.e. AmigaOS, MorphOS, AROS, WarpOS.

Defined on AmigaOS 3.

Defined on AmigaOS 4.

Defined on Android.

Defined on AROS.

Defined on iOS.

Defined on Linux.

Defined on macOS.

Defined on MorphOS.

Defined on WarpOS.

Defined on Windows.

Defined on little endian systems.

Defined on 64-bit systems.

Contains the integer part of Hollywood's version number.

Contains the fractional part of Hollywood's version number.

Note that when compiling your script into an executable, Hollywood will automatically set the constants of the target architecture instead of the build architecture. For example, if you compile your script on Windows for AmigaOS 3, Hollywood will set the constants #HW_AMIGA and #HW_AMIGAOS3. The constants #HW_WINDOWS and #HW_LITTLE_ENDIAN won't be set. They will only be set if you compile for Windows or run your script on a Windows machine.

Also note that when compiling applets, none of the architectural constants above will be set. Applets are completely platform-agnostic so if you compile an applet, none of the architectural constants will be set. An exception is if you compile an applet explicitly for Android or iOS by passing "android" or "ios" to the -exetype console argument. In that case, #HW_ANDROID and #HW_IOS, respectively, will indeed be set. If you compile a platform-independent applet by passing "applet" to the -exetype argument, though, none of the architectural constants will be set.

condition to test; must be a constant expression
The code above tells the preprocessor only to parse the following code if we have at least version 7 of Hollywood.

Show TOC