User Tools

Site Tools


This is an old revision of the document!


Augmenting GUI Editor scripts with custom script code

The GUI Editor allows users to define and design the contents and layout of the windows that compose a GUI. However, the work in the GUI Editor is focused mainly on static aspects like window position and size, texts, colors, borders, etc.

Everything “dynamic” and all sorts of effects can, by their nature, not be added by means of the GUI Editor, but must be written as custom scripts that augment the script code generated with the GUI Editor.

The question is how we can add hand-written code to the script generated by saving a GUI in the GUI Editor, without losing the custom changes when the script is modified in the GUI Editor the next time.

File Inclusion

The problem is easily solved by a shift in perspective and the dofile() script command:

For example, assume that you're using the GUI Editor in order to create a “Call Lift” GUI. Let's also assume that when done, you want to access your new GUI under the file name CallLift.cgui.

The trick is that when you save this GUI in the GUI Editor, you'd not save it under file name CallLift.cgui. Instead, you save it under file name CallLift_init.cgui. Next, create a second file next to CallLift_init.cgui with the name that you actually want, CallLift.cgui.

The new CallLift.cgui file will be the file that you actually use, and it will contain all hand-written custom code. For this to work, it must include the GUI Editor created file, and therefore its content looks like this:

dofile("Games/DeathMatch/GUIs/CallLift_init.cgui");    -- Include the GUI Editor generated file.
 
-- Add your hand-written custom code below this line.
-- ...

In summary:

  • When you edit your GUI in the GUI Editor, you only load and save file CallLift_init.cgui.
  • All hand-written code enters file CallLift.cgui instead.
  • The connection between the two files is made by the dofile() command.


Tip by Carsten Fuchs, CEO and creator of the Cafu engine:
The Games/DeathMatch/GUIs/MainMenu/MainMenu(_init).cgui files that are natively included with Cafu are prime examples of this technique.

Future versions of the GUI Editor may even mildly enforce the two-files approach, where one file has the normal file name and its “twin” gets the _init suffix automatically appended. This helps e.g. to prevent accidental overwrites when you happen to load CallLift.cgui into the GUI Editor instead of CallLift_init.cgui.

guisys/guieditor/customscripts.1246786105.txt.gz · Last modified: 2013-01-07 12:07 (external edit)