Home Memoirs of a Gamer Movies I watched Guidebook Code Projects Links

The Gorgon Engine

Events aka Routines

Script files are generally broken down into 2 things, events and non-event commands. Non-event commands are used shape the script's execution environment. Events on the other hand is where the bulk of your game's logic occurs. Each event is populated by a series of instructions that tell the virtual machine what to do with the runtime environment.

The basic format of an event follows this pattern:

event
  ::some number of instructions
endevent

The Start Event

All scripts will check for an event marked with the start keyword. Only one event can be marked as start. If no start event is found, then Gorgon will simply load the file into memory and resume gameplay. If a start event is found, it will be executed immediately.

event start
  ::instructions for initializing
  ::this script
endevent

Named Events

Events can also be given names. There are a handful of named events the engine will actively look for when certain events occur during gameplay. Named events can also be invoked by using the call instruction. The call instruction takes 2 parameters, the code segment and the desired event's name. If no event is found by that name then the current script will carry on execution. If it is found, it will be executed before returning execution to the calling event, picking back up where it left off.

call 0,"start"

This will search the Game script for an event called "start". There are several segments for scripts, each segment can only have a single script loaded into it at a time. They are:

IDUseLoaded Upon
0Primary Game ScriptAt Gorgon Initialization
1Current Roomloadroom instruction
2Auxilliary 0loadaux instruction
3Auxilliary 1loadaux instruction
4Auxilliary 2loadaux instruction
5Auxilliary 3loadaux instruction
6Auxilliary 4loadaux instruction
7Auxilliary 5loadaux instruction
8Auxilliary 6loadaux instruction
9Auxilliary 7loadaux instruction

So the above call instruction will look for an event declared like so in GAME.CNS:

event "start"
  ::some instructions
endevent

You'll notice this routine isn't flagged as the start event but is named "start". As it is not flagged with the start keyword, Gorgon will not automatically call it when the script is loaded, BUT since this event exists in the primary game script (GAME.CSN), it will be invoked if the player selects the "Restart" option from the main menu or press the F2 key. There are a few special names that Gorgon will look for under the right circumstances. They are as follows:

NameSegmentTrigger
startGAMEThe player pressing F2 or selecting "Restart" from the main menu
tickROOMAt the start of every game tick
saidROOMWhenever the player has entered a command into the parser and pressed the ENTER key