7.8 Automatic ID selection

You can pass Nil to all functions that ask you to specify a vacant identifier for the new Hollywood object. In that case, Hollywood will automatically choose a vacant identifier and return it to you. This is especially useful for larger projects. If your project is small it is more convenient to use hard-coded ids, e.g.

 
LoadBrush(1, "brush1.iff")
LoadBrush(2, "brush2.iff")
LoadSample(1, "sample.wav")
OpenFile(1, "file.txt")

However, when your project grows larger id management can get quite confusing and nobody wants to mess around with a myriad of different ids. Thus, you can simply pass Nil instead of an id and Hollywood will return an id for the new object that is guaranteed to be unique because it uses the special variable type #LIGHTUSERDATA. That way, it is ensured that no id conflicts will arise because if you pass Nil, Hollywood will not choose an id from the id pool (i.e. integer numbers from 1 to n) but it will create unique ids. Thus, all normal ids will still be available for use, e.g.

 
brush1 = LoadBrush(Nil, "brush1.iff")
brush2 = LoadBrush(Nil, "brush2.iff")
sample1 = LoadSample(Nil, "sample.wav")
file1 = OpenFile(Nil, "file.txt")

The variables brush1, brush2, sample1, and file1 will not receive any human readable ids but special ids of type #LIGHTUSERDATA. Thus, all human readable ids from 1 to n will still be available. Therefore, you do not have to worry about any id conflicts when passing Nil to object creation function, because they cannot occur as Hollywood uses two separate id dimensions: One human readable that is only used when you pass an id to the object creation functions and one opaque id mechanism that is used when you pass Nil to the object creation functions.


Show TOC