Home
Memoirs of a Gamer
Movies I watched
Guidebook
Code Projects
Links
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 |
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 |
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:
ID | Use | Loaded Upon |
0 | Primary Game Script | At Gorgon Initialization |
1 | Current Room | loadroom instruction |
2 | Auxilliary 0 | loadaux instruction |
3 | Auxilliary 1 | loadaux instruction |
4 | Auxilliary 2 | loadaux instruction |
5 | Auxilliary 3 | loadaux instruction |
6 | Auxilliary 4 | loadaux instruction |
7 | Auxilliary 5 | loadaux instruction |
8 | Auxilliary 6 | loadaux instruction |
9 | Auxilliary 7 | loadaux 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:
Name | Segment | Trigger |
start | GAME | The player pressing F2 or selecting "Restart" from the main menu |
tick | ROOM | At the start of every game tick |
said | ROOM | Whenever the player has entered a command into the parser and pressed the ENTER key |