4.3 Linking data files

By default, Hollywood's linker will automatically link all external data files declared using preprocessor commands to the output executable or applet. If your script looks like below, for example, the file test.jpg will automatically be linked to your executable or applet:

 
@BGPIC 1, "test.jpg"
WaitLeftMouse
End

If you don't want that, you can set the Link tag, which is accepted by all preprocessor commands dealing with files, to False. In that case, the file referenced by the preprocessor command will not be linked. The code looks like this then:

 
@BGPIC 1, "test.jpg", {Link = False}
WaitLeftMouse
End

Sometimes, you might also want to link files that are loaded by your script at runtime into your executable or applet. Consider the following code for example:

 
LoadBGPic(1, "test.jpg")
LoadBrush(1, "title.png")
DisplayBGPic(1)
DisplayBrush(1, #CENTER, #CENTER)
WaitLeftMouse
End

By default, test.jpg and title.png won't be linked to your executable or applet because they haven't been declared in a preprocessor command but they are loaded at runtime using LoadBGPic() and LoadBrush() instead. Still, it is possible to link test.jpg and title.png to your executable or applet. This can be achieved by using either the ‘-linkfiles’ compiler option or the @LINKER preprocessor command.

When using the ‘-linkfiles’ console argument, you need to pass a database file to it. The database file is a simple UTF-8 text file which contains a list of files to be linked into the applet or executable that will be compiled by Hollywood. You must only specify one file per line in the database file. The file specification must be identical to the specification you use in your script. For example, if there is a command LoadBrush(1, "data/menu.png") in your script and you want the file data/menu.png to be linked into your applet or executable, you need to put it into the database you pass to ‘-linkfiles’. But you must use the same specification, i.e. you need to use data/menu.png! Specifying MyScripts/CoolGame/data/menu.png in the database will not work! The specification used in the link files database and in the script must be the same because otherwise Hollywood cannot know which file it must load.

So in order to link the files test.jpg and title.png to our executable or applet, the database file we pass to ‘-linkfiles’ needs to look like this:

 
test.jpg
title.png

That is all! The Hollywood linker will then link test.jpg and title.png to the output executable or applet and the calls to LoadBGPic() and LoadBrush() in the script presented above will load test.jpg and title.png, respectively, directly from the executable or applet instead of from an external source.

The same can be achieved by using the @LINKER preprocessor command. The only difference is that the files to be linked don't have to be passed in an external database file to Hollywood, but they must be stored directly in your script as part of the @LINKER preprocessor command instead. All other rules are the same as with ‘-linkfiles’. So if you don't want to use ‘-linkfiles’ like above, you could also just add the following line to your script and achieve the same:

 
@LINKER {Files = {"test.jpg", "title.png"}}

You can add as many files as you want to have linked to your applet or executable to the Files tag that is part of the @LINKER preprocessor command. Just make sure the path specification of the files you pass to @LINKER is identical to the path specification used later in the code so that Hollywood can correctly map the linked files to the individual files used in the script.

If you need to link lots of files to your applet or executable, you can put all those files into a directory and then tell Hollywood to link everything in that directory to the applet or executable. This is done by using @DIRECTORY preprocessor command. For example, the following line tells Hollywood to link all files inside the data directory to the applet or executable:

 
@DIRECTORY 1, "data"

Once you have done that, you can then access the individual files in the data directory by using the GetDirectoryEntry() function. For example, to load the files data/test.jpg and data/title.png using LoadBGPic() and LoadBrush(), you would write the following code:

 
LoadBGPic(1, GetDirectoryEntry(1, "data/test.jpg"))
LoadBrush(1, GetDirectoryEntry(1, "data/title.png"))

The @DIRECTORY preprocessor command is very flexible because it will archive the complete directory tree inside an applet or executable which also makes it possible to iterate through the directory (and all of its subdirectories!) as if it were a real one. See DIRECTORY for details.


Show TOC