GameLogic

Contains general game-related functions.

About

This is a global object that can always be accessed.

Usage

GetGameLogic:Quit(); //quits the game

Profile Related

SetUserProfileName

boolean SetUserProfileName(string name)

Re-initializes everything and attempts to load the profile sent in.  Think of this as loading a saved game.  If no profile exists, it is created.

Dangerous and illegal characters are stripped automatically, so the profile name may be slightly different than the one you sent in.

Parameters

namethe name of the profile.  If you say, “Player”, it will create/load/save profiles/Player/(active world name).

Returns

False on error (for instance, the name passed in is not a valid path, or tries to access somewhere illegal), true on success

GetUserProfileName

string GetUserProfileName()

Returns

The active user profile name.  Will return a blank string if empty.  (ie, “”, not nil)

ResetUserProfile

nil ResetUserProfile(string name)

This completely deletes a profile, if it existed.

Input is stripped of dangerous/illegal characters.

Parameters

nameThe profile name you want to delete.

Note

Novashell never uses a dangerous deltree type way to delete things, it carefully verifies and scans the directory deletes only valid novashell data.

UserProfileExists

boolean UserProfileExists(string name)

Parameters

nameThe profile name you want to check for.  Is stripped for dangerous/illegal characters.

Returns

True if the profile exists.

UserProfileActive

boolean UserProfileActive()

Returns

True if a user profile is currently loaded/active.

Miscellaneous Functions

ToggleEditMode

boolean ToggleEditMode()

Enable/Disable the in-game editor.

Returns

True if the it just turned ON the editor, false if it was just turned off

SetRestartEngineFlag

nil SetRestartEngineFlage(boolean bRestart)

Parameters

bRestartIf true, the engine will save all modified data and restart as soon as cybernetic ally possible.

AddCallbackOnPostLogicUpdate

nil AddCallbackOnPostLogicUpdate(string callbackName, number entityID)

Allows you to add a function to be called after the entities logic updates happen.  I added this as an easy way to make a game loop without needing to connect it with an entity.

The callback is automatically deleted when an Entity dies.  In the case of a global function, there is no way to unregister it.

Note

It must accept a single parm, this “Step” is a number that contains the ‘step-size’ used in the logic update, similar to an entities Update(step).

Usage

//Example to make a global game loop function, run this somewhere at the start:
GetGameLogic:AddCallbackOnPostLogicUpdate("OnGameLoop", C_ENTITY_NONE);

//this is run every logic tick

function OnGameLoop(step)
LogMsg("Game loop update");

//shake the camera randomly.. earthquake!
GetCamera:SetPos(GetCamera:GetPos() + Vector2(10-Random(20), 10-Random(20)));

end

Parameters

string callBackNameThe name of the callback function that should be called.  (Must exist in your code)
entityIDIf it’s an Entity function and not a global function, you’ll need to enter the Entity’s ID here.  Otherwise, <C_ENTITY_NONE>.

IsShuttingDown

boolean IsShuttingDown()

When a game is closing or restarting all maps are ‘shutdown’.  During this time, each entity has its OnKill() run, during times like this is may be useful to know if the engine is currently shutting down or not, to avoid trying to access things that might already be deleted.

Returns

True if the engine is currently shutting down.  (Either to exit, or to restart, both have the same shutdown process)

ClearModPaths

nil ClearModPaths()

Removes all overlaid paths.  This should be done right before doing a SetRestartEngineFlag() call.  Allows you to re-mount directories or go back to the world selection dialog.  (that’s default if no mods are mounted)

AddModPath

nil AddModPath(string pathName)

This lets you mount a world path.  Scripts, images, and resources are loaded in reverse order of mounting, ie, the last thing you mounted gets checked first.

Note

”Base” is always mounted first automatically.

Worlds are also automatically mounted if specified in its .novashell configuration file.

Parameters

pathNameA name of a world to mount.  Example: “Test World”.

InitGameGUI

nil InitGameGUI(string xmlFileName)

This xml file contains data about fonts, sizes, and colors that should be used for game dialogs and menus.

By editing this, you can use your own custom bitmap fonts.

Check the default one in base/game_gui/standard.xml for an example.

Note

A world can only initialize this once.

Parameters

xmlFileNameA path and filename to an xml file.

Data

DataManager Data()

This let’s you access a global DataManager that is automatically saved and loaded with the game per user profile.

Note

Never use DataManager::Clear on this, the save-load game system uses it to store certain things as well, such as the game time.

Returns

A global DataManager object to store/retrieve anything you wish per profile.

WorldData

DataManager WorldData()

This let’s you access a global DataManager that is automatically saved and loaded with the game.

Note

Unlike <DataManager::Data> because it is shared between profiles.  Useful for specifying global game tweaking variables that will never change for instance.

Returns

A global DataManager object to store/retrieve anything you wish.

Quit

nil Quit()

Immediately closes the application.  Changed game data is auto-saved.

The Entity object.
An object designed to flexibly store and retrieve numbers and strings very quickly use key/value pairs.