Contents Up Previous Next

Game / Global functions

CallRoomScript
Debug
DisableInterface
EnableInterface
EndCutscene
GetGameSpeed
GetGlobalInt
GetLocationName
GetLocationType
GetSaveSlotDescription
GetTime
GetTranslation
GetTranslationName
GiveScore
IsButtonDown
IsGamePaused
IsInterfaceEnabled
IsInteractionAvailable
IsKeyPressed
IsTimerExpired
IsTranslationAvailable
PauseGame
ProcessClick
QuitGame
Random
RefreshMouse
RestartGame
RestoreGameDialog
RestoreGameSlot
SaveGameDialog
SaveGameSlot
SaveScreenShot
SetGameSpeed
SetGlobalInt
SetNormalFont
SetRestartPoint
SetTimer
StartCutscene
UnPauseGame
Wait
WaitKey
WaitMouseKey


CallRoomScript

CallRoomScript (int value)
Calls the on_call function in the current room script. This is useful for things like the text parser, where you want to check for general game sentences, and then ask the current room if the sentence was relevant to it.

The on_call function will be called in the current room script, with its value parameter having the value you pass here. This allows it to distinguish between different tasks, and saves you having to use a GlobalInt to tell it what to do.

If the current room has no on_call function, nothing will happen. No error will occur.

You write the on_call function into the room script ("Edit script" button on Room Settings pane), similar to the way you do dialog_request in the global script:

function on_call (int value) {
  if (value == 1) {
    // Check text input
    if (Said("get apple"))
      Display("No, leave the tree alone.");
  }
}
The function doesn't get called immediately; instead, the engine will run it in due course, probably during the next game loop, so you can't use any values set by it immediately.

Once the on_call function has executed (or not if there isn't one), the game.roomscript_finished variable will be set to 1, so you can check for that in your repeatedly_execute script if you need to do something afterwards.

SeeAlso: The text parser documentation


Debug

Debug (int command, int data)
This function provides all the debug services in the system. It performs various different tasks, depending on the value of the COMMAND parameter. If debug mode is off, then this function does nothing. This allows you to leave your script unaltered when you distribute your game, so you just have to turn off debug mode in the Room Editor.

The DATA parameter depends on the command - pass 0 if it is not used. All the valid values for the COMMAND parameter are listed below along with what they do:

0   All inventory - gives the current player character one of every
    inventory item. This is useful for testing so that you don't have to
    go and pick up items every time you test part of the game where they
    are required.
1   Display interpreter version - the engine will display its version
    number and build date.
2   Walkable from here - fills in the parts of the screen where the player
    can walk from their current location. This is useful if you think the
    path-finder is not working properly. Yellow areas are where the man
    can walk. Blue areas are defined as walkable in the Room Editor, but
    he cannot get to them from his current position. The unaltered parts
    of the screen are not walkable.
3   Teleport - displays a dialog box asking for what room you want to go
    to, and then calls NewRoom to teleport you there. Useful for skipping
    parts of the game or going to a specific point to test something.
4   Show FPS - toggles whether the current frames per second is displayed
    on the screen. Pass DATA as 1 to turn this on, 0 to turn it off.

DisableInterface

DisableInterface ()
Disables the player interface. This works the same way as it is disabled while an animation is running: the mouse cursor is changed to the Wait cursor, and mouse clicks will not be sent through to the "on_mouse_click" function. Also, all interface buttons will be disabled.

Example:

DisableInterface();
will disable the user’s interface.

See Also: EnableInterface, IsInterfaceEnabled


EnableInterface

EnableInterface ()
Re-enables the player interface, which was previously disabled with the DisableInterface function. Everything which was disabled is returned to normal.

Example:

EnableInterface();
will enable the user’s interface.

See Also: DisableInterface, IsInterfaceEnabled


EndCutscene

EndCutscene()
Marks the end of a cutscene. If the player skips the cutscene, the game will fast-forward to this point. This function returns 0 if the player watched the cutscene, or 1 if they skipped it.

See Also: StartCutscene


GetGameSpeed

GetGameSpeed ()
Returns the current game speed (number of cycles per second).

Example:

if (GetGameSpeed() > 40) {
  SetGameSpeed(40);
}
will always keep the game speed at 40 cycles per second (in case the user has raised it )

See Also: SetGameSpeed


GetGlobalInt

GetGlobalInt (int index)
Returns the value of global variable INDEX.

Example:

if (GetGlobalInt(20)==1)
   { code hre } 
will execute the code only if Global Integer 20 is 1.

See Also: SetGlobalInt


GetLocationName

GetLocationName (int x, int y, string buffer)
Fills in BUFFER with the name of whatever is on the screen at (X,Y). This allows you to create the Lucasarts-style status lines reading "Look at xxx" as the player moves the cursor over them.

NOTE: Unlike ProcessClick, this function actually works on what the player can see on the screen - therefore, if the co-ordinates are on a GUI, a blank string is returned.

NOTE: The co-ordinates are SCREEN co-ordinates, NOT ROOM co-ordinates. This means that with a scrolling room, the co-ordinates you pass are relative to the screen's current position, and NOT absolute room co-ordinates. This means that this function is suitable for use with the mouse cursor position variables.

Example:

string buffer;
GetLocationName(mouse.x, mouse.y, buffer);
will pass the location’s where the mouse is over name to the string buffer.

See Also: GetInvName, GetLocationType


GetLocationType

GetLocationType (int x, int y)
Returns what type of thing is at location (X,Y); whether it is a character, object, hotspot or nothing at all. This may be useful if you want to process a mouse click differently depending on what the player clicks on.

NOTE: The co-ordinates are screen co-ordinates, NOT room co-ordinates. See description of GetLocationName for more info.

The value returned means that the location is:

0   nothing, GUI or inventory
1   a hotspot
2   a character
3   an object
Example:
if (GetLocationType(mouse.x,mouse.y)==2)
    SetCursorMode (MODE_TALK); 
will set the cursor mode to talk if the cursor is over a character.

See Also: GetHotspotAt, GetLocationName, GetObjectAt


GetSaveSlotDescription

GetSaveSlotDescription (int slot, string buffer)
Gets the text description of save game slot SLOT into the provided BUFFER. If the slot number provided does not exist this function returns 0, if successful it returns 1.

Example:

string buffer;
GetSaveSlotDescription(10,buffer);
will pass the description of the save game slot 10 to buffer.

See Also: RestoreGameSlot, SaveGameSlot


GetTime

GetTime (int whichvalue)
This function returns various values, representing the current system time. You could use this for timing a loop, or for effects like telling the player to go to bed, and so on.

The WHICHVALUE parameter controls what is returned:

1  current hour (0-23)
2  current minute (0-59)
3  current second (0-59)
4  current day (1-31)
5  current month (1-12)
Example:
if ((GetTime(1)==0) && (GetTime(2)==0) && (GetTime(3)==0))
    Display ("It’s midnight, time to go to bed");
will display a message to go to bed at midnight.


GetTranslation

GetTranslation (string original)
Gets the translated equivalent of the supplied string. You do not normally need to use this since the game translates most things for you. However, if you have used an InputBox or other form of user input, and want to compare the user's input to a particular string, it cannot be translated automatically. So, you can do this instead.

Example:

string buffer;
InputBox ("Enter the password:", buffer);
if (StrComp (buffer, GetTranslation ("secret")) == 0) {
  // it matched the current translation of "secret"
}
If there is no translation for the supplied string, it will be returned unchanged, so it is always safe to use this function.

See Also: IsTranslationAvailable


GetTranslationName

GetTranslationName (string buffer)
Places the name of the current translation file into BUFFER. This may be useful if you want to use a different graphic somewhere depending on which translation is being used.

BUFFER is filled with the current translation filename (without the ".tra" extension). If no translation is in use, it is set to an empty string.

Returns 1 if a translation is in use, 0 otherwise.

Example:

string buffer;
GetTranslationName(buffer);
if (StrCaseComp(buffer, "German") == 0) {
  Display("You are using the German translation.");
}
See Also: IsTranslationAvailable


GiveScore

GiveScore (int score)
Adds SCORE to the player's score. This is preferable to directly modifying the variable since it will play the score sound, update any status lines and call the GOT_SCORE on_event function.

Note that SCORE can be negative, in which case the score sound is NOT played.

Example:

GiveScore(5);
will give 5 points to the player.


IsButtonDown

IsButtonDown ( BUTTON )
Tests whether the user has the specified mouse button down. BUTTON is either LEFT or RIGHT. Return 1 if the button is currently pressed, 0 if not. This could be used to test the length of a mouse click and similar effects.

Example:

int timer=0;
if (IsButtonDown(RIGHT)==1)
   { if (timer==40) 
        {Display ("You pressed the right button for 1 sec");
         timer=0; }       
     else  timer++; }      
will display the message if the player presses the right button for 1 sec.

See Also: IsKeyPressed


IsGamePaused

IsGamePaused ()
Returns 1 if the game is currently paused, or 0 otherwise. The game is paused when either the icon bar interface has been popped up, or a "script-only" interface has been displayed with GUIOn. While the game is paused, no animations or other updates take place.

Example:

if (IsGamePaudsed() == 1) UnPauseGame();
will unpause the game if it’s paused.

See Also: GUIOn


IsInterfaceEnabled

IsInterfaceEnabled ()
Returns 1 if the player interface is currently enabled, 0 if it is disabled. The user interface is disabled while the cursor is set to the Wait cursor - ie. while the character is performing a blocking Walk, or other blocking action.

Example:

if (IsInterfaceEnable()==1)
    DisableInterface();
will disable the user interface if it’s enabled.

See Also: DisableInterface, EnableInterface


IsInteractionAvailable

IsInteractionAvailable (int x, int y, int mode)
Checks whether there is an interaction defined for clicking on the screen at (X,Y) in cursor mode MODE.

This function is very similar to ProcessClick, except that rather than carry out any interactions it encounters, it simply returns 1 if something would have happened, or 0 if unhandled_event would have been run.

This is useful for enabling options on a verb-coin style GUI, for example.

Example:

if (IsInteractionAvailable(mouse.x,mouse.y,MODE_LOOK) == 0)
  Display("looking here would not do anything.");
See Also: ProcessClick


IsKeyPressed

IsKeyPressed (int keycode)
Tests whether the supplied key on the keyboard is currently pressed down or not. You could use this to move an object while the player holds an arrow key down, for instance.

KEYCODE is one of the ASCII codes from section 6.6, with some limitations: since it tests the raw state of the key, you CANNOT pass the Ctrl+(A-Z) or Alt+(A-Z) codes (since they are key combinations). You can, however, use some extra codes which are listed at the bottom of the section.

Returns 1 if the key is currently pressed, 0 if not.

Example:

if (IsKeyPressed(372) == 1)
  MoveCharacter(EGO,character[EGO].x,character[EGO].y+3);
will move the character EGO upwards 3 pixels when the up arrow is pressed.

See Also: IsButtonDown


IsTimerExpired

IsTimerExpired (int timer_id)

Checks whether the timer TIMER_ID has expired. If the timeout set with SetTimer has elapsed, returns 1. Otherwise, returns 0.

Note that this function will only return 1 once - after that, the timer is placed into an OFF state where it will always return 0 until restarted.

Example:

If (IsTimerExpired(1)==1)
    {code here} 
will execute the code if the timer 1 expires.

See Also: SetTimer


IsTranslationAvailable

IsTranslationAvailable ()
Finds out whether the player is using a game translation or not.

Returns 1 if a translation is in use, 0 if not.

See Also: GetTranslation, GetTranslationName


PauseGame

PauseGame ()
Stops the engine processing character movement and animation, and other game features. This has the same effect on the game as happens when a script-only interface is popped up. The processing will not resume until you call the UnPauseGame function.

Example:

if (IsKeyPressed(32)==1) PauseGame();
will pause the game if the player presses the space bar

See Also: UnPauseGame


ProcessClick

ProcessClick (int x, int y, int mode)
Simulates clicking the mouse on the location (X,Y) on the screen, in the cursor mode MODE. Any conditions attached will be executed. For example,
ProcessClick (100, 50, MODE_LOOK);
will simulate clicking the mouse on co-ordinates (100,50) in the Look mode.

NOTE: This function ignores all interfaces and acts as though the point is directly visible. In other words, if the co-ordinates you pass happen to lie on a button on an interface, what actually happens will be as if the user clicked behind the interface onto the actual screen.

Available cursor modes: MODE_WALK, MODE_LOOK, MODE_USE, MODE_TALK, MODE_USEINV, MODE_PICKUP.

Example:

ProcessClick(mouse.x,mouse.y,MODE_LOOK);
will simulate a click in the LOOK MODE where the cursor is.

See Also: IsInteractionAvailable, RunHotspotInteraction


QuitGame

QuitGame(int ask_first)
Exits the game and returns to the operating system (DOS, Windows, etc).

If ASK_FIRST is zero, it will exit immediately. If ASK_FIRST is not zero, it will first display a message box asking the user if they are sure they want to quit.

Example:

QuitGame(0);
will quit the game without asking the player to confirm.


Random

Random (int max)
Returns a random number between 0 and MAX. This could be useful to do various effects in your game.

Example:

int ran=Random(2);
if (ran==0) NewRoom(1);
else if (ran==1) NewRoom(2);
else NewRoom(3);
will change the current room to room 1,2 or 3 depending on a random result.


RefreshMouse

RefreshMouse ()
Updates the global variables "mouse.x" and "mouse.y" with the current position of the mouse. Normally, these variables are set just before each script function is executed. However, if you have a very long script where the mouse may have moved since the start of the function, and you need the exact current location, then RefreshMouse will update the variables.


RestartGame

RestartGame ()
Restarts the game from the beginning.

Example:

if (IsKeyPressed(365) == 1) RestartGame(); 
will restart the game if the player presses the F7 key.


RestoreGameDialog

RestoreGameDialog ()
Displays the restore game dialog, where the player can select a previously saved game position to restore.

The dialog is not displayed immediately; instead, it will be displayed when the script function finishes executing.

Example:

if (IsKeyPressed(363)=1 RestoreGameDialog();
will bring up the restore game dialog if the player presses the F5 key.

See Also: RestoreGameSlot, SaveGameDialog


RestoreGameSlot

RestoreGameSlot (int slot)
Restores the game position saved into slot number SLOT. You might want to use these specific slot functions if for example you only want to allow the player to have one save game position rather than the usual 20. If this slot number does not exist, an error message is displayed to the player but the game continues. To avoid the error, use the GetSaveSlotDescription function to see if the position exists before restoring it.

NOTE: The position will not be restored immediately; instead, it will be restored when the script function finishes executing.

Example:

RestoreGameSlot(30);
will restore game slot 30 if this slot number exists.

See Also: GetSaveSlotDescription, RestoreGameDialog, SaveGameSlot


SaveGameDialog

SaveGameDialog ()
Displays the save game dialog, where the player can save their current game position. If they select to save, then the game position will be saved.

Example:

if (IsKeyPressed(361)=1 SaveGameDialog();
will bring up the save game dialog if the player presses the F3 key.

See Also: RestoreGameDialog, SaveGameSlot


SaveGameSlot

SaveGameSlot (int slot, string description)
Saves the current game position to the save game number specified by SLOT, using DESCRIPTION as the textual description of the save position. Be careful using this function, because you could overwrite one of the player's save slots if you aren't careful. The SaveGameDialog function uses slots numbered from 1 to 20, so if you don't want to interfere with the player's saves, I would recommend saving to slot numbers of 100 and above.

Example:

SaveGameSlot (30, "save game");
will save the current game position to slot 30 with the description "Save game".

See Also: RestoreGameSlot, SaveGameDialog


SaveScreenShot

SaveScreenShot (string filename)
Takes a screen capture and saves it to disk. The FILENAME must end in either ".BMP" or ".PCX", as those are the types of files which can be saved. Returns 1 if the shot was successfully saved, or 0 if an invalid file extension was provided.

Example:

string input;
InputBox("type the filename",input);
SrtCat (input,".pcx");
Savescreenshot (input);
will prompt the player for a filename and then save the screenshot with the filename the player typed.


SetGameSpeed

SetGameSpeed (int new_speed)
Sets the game speed to NEW_SPEED frames per second, or as near as possible to that speed. The default frame rate is 40 fps, but you can speed up or slow down the game by using this function. Note that this speed is also the rate at which the Repeatedly_Execute functions are triggered. The NEW_SPEED must lie between 10 and 100. If it does not, it will be rounded to 10 or 100. Note that if you set a speed which the player's computer cannot handle (for example, a 486 will not be able to manage 80 fps), then it will go as fast as possible. NOTE: Because the mouse cursor is repainted at the game frame rate, at very low speeds, like 10 to 20 fps, the mouse will appear to be jumpy and not very responsive.

Example:

SetGameSpeed(80);
will set the game speed to 80.

See Also: GetGameSpeed


SetGlobalInt

SetGlobalInt (int index, int value)
Sets the global variable INDEX to VALUE. You can then retrieve this value from any other script using GetGlobalInt. There are 300 available global variables, from index 0 to 299.

Example:

SetGlobalInt(10,1);
will set the Global Integer 10 to 1.

See Also: GetGlobalInt


SetNormalFont

SetNormalFont (int font_number)
Changes the font used for all in-game text, except speech. FONT_NUMBER must be from 0 to the number of fonts you have. By default the only options are 0 and 1.

Example:

SetNormalFont(4);
will change the normal font to the font number 4.

See Also: SetSpeechFont


SetRestartPoint

SetRestartPoint ()
Changes the game restart point to the current position. This means that from now on, if the player chooses the Restart Game option, it will return here.

This function is useful if the default restart point doesn't work properly in your game - just use this function to move it.


SetTimer

SetTimer (int timer_id, int timeout)
Starts timer TIMER_ID ticking - it will tick once every game loop (normally 40 times per second), until TIMEOUT loops, after which it will stop. You can check whether the timer has finished by calling the IsTimerExpired function.

Pass TIMEOUT as 0 to disable a currently running timer.

There are 20 available timers, with TIMER_IDs from 1 to 20.

Example:

SetTimer(1,1000); 
will set the timer 1 to expire after 1000 game cycles.

See Also: IsTimerExpired


StartCutscene

StartCutscene (int skip_with)
Marks the start of a cutscene. Once your script passes this point, the player can choose to skip a portion by pressing a key or the mouse button. This is useful for things like introduction sequences, where you want the player to be able to skip over an intro that they've seen before.

SKIP_WITH determines how they can skip the cutscene:

1  by pressing ESC only
2  by pressing any key
3  by clicking a mouse button
4  by pressing any key or clicking a mouse button
5  by pressing ESC or clicking the right mouse button
You need to mark the end of the cutscene with the EndCutscene command.

Be very careful with where you place the corresponding EndCutscene command. The script must pass through EndCutscene in its normal run in order for the skipping to work - otherwise, when the player presses ESC the game could appear to hang.

See Also: EndCutscene


UnPauseGame

UnPauseGame ()
Resumes the game.

Example:

if (IsGamePaused() == 1)
    UnPauseGame();
will unpause the game if it is paused.

See Also: PauseGame


Wait

Wait (int time)
Pauses the script and lets the game continue for TIME loops. There are normally 40 loops/second (unless you change it with SetGameSpeed), so using a value of 80 will wait 2 seconds. Note that no other text scripts can run while the Wait function is in the background.

Example:

MoveCharacterBlocking(EGO,120,140,0);
Wait(80);
FaceLocation(EGO,1000,100);
will move the character EGO to 120,140, wait until he gets there (MoveCharacterBlocking) then wait for 2 seconds (80 game cycles) and then face right.

See Also: WaitKey, WaitMouseKey


WaitKey

WaitKey (int time)
Pauses the script and lets the game continue until EITHER:

(a) TIME loops have elapsed, or

(b) the player presses a key

Returns 0 if the time elapsed, or 1 if the player interrupted it.

Example:

WaitKey(200);
will pause the script and wait until 5 seconds have passed or the player presses a key.

See Also: Wait, WaitMouseKey


WaitMouseKey

WaitMouseKey (int time)
Pauses the script and lets the game continue until EITHER:

(a) TIME loops have elapsed, or

(b) the player presses a key, or

(c) the player clicks a mouse button

Returns 0 if the time elapsed, or 1 if the player interrupted it.

Example:

WaitMouseKey(200);
will pause the script and wait until 5 seconds have passed or the player presses a key or clicks the mouse.

See Also: Wait, WaitKey