Building on the code I developed for the Babylon 5 mod's Area Capture game script, I've created a small set of scripts that will allow you to pass numerical information between the .level files and the game rules:
alternate link until Moddb clears the file:
This should open up a whole load of possibilities for customising maps to a much greater extent than is currently possible. For example you could create a script that takes values stored in the level file to create customised, scripted events on a per-level basis.
Its pretty simple to use. The script consists of two parts, one which has to be loaded by the various level files and another part which has to be loaded in the relevant game rule.
Inside Level Files:
The scripts/scar/LevelLink/level.lua file is the level side of the link and should be imported at the start of the level file. To create the link, LinkOpen() should first be called in the deterministic section of the level file. LinkSet(sVarName, fValue) commands, following the LinkInit() command, can then be used to pass named values to the game rule. ie:
Inside Game rule:
The scripts/scar/LevelLink/gamerule.lua is the game rule side of the link and should be imported at the start of the game rule file. LinkGet(sVarName, fValue) can then be used to recover the variables set in the level file via LinkSet(). Once all variables have been recovered, LinkClose() must be called to clean up sobgroups and objects used to pass the between data the level and game files. ie:
For those that are interested it works like so:
yourvar1 = LinkGet("yourvarname1")
yourvar2 = LinkGet("yourvarname2")
yourvar3 = LinkGet("yourvarname3")
yourvar4 = LinkGet("yourvarname4")
The level script - A reference object and sobgroup are created. For each variable defined by the user in the level file, the variable's value is is encoded as a IEEE754 double (64-bit). A volume is created for each bit, with the volume either created surrounding the reference object or not depending on the value of each bit. The bits are named by the variable names set in the level file.
The game rule script - when the user requests a variable the volumes associated with that variable's bits are checked to see if they contain the reference object. If they do the bit is 1 if not the bit is 0. The bits are then decoded back into a normal number and are then assigned to a normal lua variable. A cleanup routine removes the reference object and sobgroup.
Give it a try, the possibilities are endless! For the Babylon 5 mod we intend to use this to allow map makers to provide customised hazards/events to maps such as groups of non-player/AI ships that guard areas of the map.