Module TheoTown
TheoTown specific functions that don't fit into other libraries.
Functions
getDiamonds () | Returns the number of diamonds that the user currently has. |
getFileStorage () | Returns a game wide storage table that's backed by an actual file. |
getGlobalFunVar (name[, fallbackValue]) | Returns the value of the global fun variable of the given name or fallbackValue if no such variable has been defined, yet. |
getPlayTime () | Returns the play time in the game in seconds. |
getStorage () | Returns a game wide storage table. |
getUserName () | Returns the name of the current logged in user or nil if the player is not logged in. |
isMultiplayer () | Returns true iff this version of the game is capable of running multiplayer games. |
playSound (sound[, volume=1[, loop=false]]) | Plays a sound. |
registerCommand (name, action) | Registers a function that can then by called from console. |
setGlobalFunVar (name, value) | Sets the value of a global fun variable called name. |
spendDiamonds (amount) | Spends amount diamonds if possible. |
translate (id) | Translates an id into the corressponding string. |
translateInline (str) | Resolves the translation of an inline translation string. |
Functions
- getDiamonds ()
-
Returns the number of diamonds that the user currently has.
Returns:
-
number
- getFileStorage ()
-
Returns a game wide storage table that's backed by an actual file.
The file will even persist if the user deleted the game. Only a deletion
of the TheoTown folder will reset this storage.
Returns:
- getGlobalFunVar (name[, fallbackValue])
-
Returns the value of the global fun variable of the given name or
fallbackValue if no such variable has been defined, yet.
fallbackValue is 0 by default.
Note that fun variables can only contain numbers. Use City.getStorage()
or TheoTown.getStorage() to store more fancy stuff.
Global fun variables are indicated by a leading ! in their name.
Parameters:
- name string
- fallbackValue number (optional)
Returns:
-
number
- getPlayTime ()
-
Returns the play time in the game in seconds.
Returns:
-
number
Time in seconds.
- getStorage ()
-
Returns a game wide storage table. Use it to save data permanently accross
all cities.
Returns:
- getUserName ()
-
Returns the name of the current logged in user or nil if the player is not
logged in.
Returns:
-
string
Name of the current user or nil if the player is not
logged in.
- isMultiplayer ()
-
Returns true iff this version of the game is capable of running multiplayer
games.
Returns:
-
bool
- playSound (sound[, volume=1[, loop=false]])
-
Plays a sound.
Parameters:
- sound draft A sound draft or id of a sound draft.
- volume number A value between 0 and 1. (default 1)
- loop boolean Whether or not to loop the sound. (default false)
Returns:
-
table
A table that contains functions to control the sound.
- registerCommand (name, action)
-
Registers a function that can then by called from console.
Instead of a name you can provide a function that returns true for commands
the second function should handle.
Parameters:
- name string or function
- action function A function that will be called when the command got entered.
Usage:
TheoTown.registerCommand('test', function(name, arg) return arg -- Will be displayed as result end)
- setGlobalFunVar (name, value)
-
Sets the value of a global fun variable called name.
Note that fun variables can only contain numbers. Use City.getStorage()
or TheoTown.getStorage() to store more fancy stuff.
Global fun variables are indicated by a leading ! in their name.
Parameters:
- name string
- value number
- spendDiamonds (amount)
-
Spends amount diamonds if possible. Returns true iff spending was successful,
false otherwise.
Parameters:
- amount number
- translate (id)
-
Translates an id into the corressponding string.
Instead of TheoTown.translate('key') you can write Translation.key
for convenience.
Parameters:
- id string The id of a translation to translate.
Returns:
-
string
The translation.
- translateInline (str)
-
Resolves the translation of an inline translation string.
Such a string may look like "default[de]German[fr]French...".
The function will be the ppropriate part based on language settings.
Parameters:
- str string A packed string to prick a translation from.
Returns:
-
string
The picked translation.