World of Hello
Static Public Member Functions | List of all members
game Class Reference

the game program/application. More...

#include <game.h>

Static Public Member Functions

static int getWindowX (bool dpiAware=true)
 get the window's x. More...
 
static int getWindowY (bool dpiAware=true)
 get the window's y. More...
 
static int getWindowWidth (bool dpiAware=true)
 get the window's width. More...
 
static int getWindowHeight (bool dpiAware=true)
 get the window's height. More...
 
static elementgetElementFromID (string ID)
 get a GUI element from an ID. More...
 
static elementgetElementFromPosition (int x, int y)
 gets an element from an absolute position. More...
 
static meshgetMeshFromID (string ID)
 get a mesh from an ID. More...
 
static game setTitle (string title="")
 sets the window title. More...
 
static game loadScripts (string filePath)
 load a script or scripts in a directory. More...
 
static bool scriptLoaded (string filePath)
 checks whether or not the script has loaded. More...
 
static string[] getScripts (string folder="", string filter="")
 get a table of all running script names. More...
 
static string getScript (string filePath)
 get the code to the script with the given file path. More...
 
static game setScript (string filePath, string code, bool remove=false)
 set the code of the script with the given file path. More...
 
static game setKeyDown (string key)
 set a key down. More...
 
static game reload ()
 reload all scripts. More...
 
static game getOpenFileName (function func,...)
 get a selected file from the operating system's file browser. More...
 
static game getSaveFileName (function func,...)
 choose a file location to save using the operating system's file browser. More...
 
static game drawRectangle (int x, int y, int width=100, int height=50, bool border=false, int r=0, int g=0, int b=0, int a=255, int clipX=0, int clipY=0, int clipWidth=game:getWindowWidth(), int clipHeight=game:getWindowHeight())
 draw a rectangle onto the screen. More...
 
static game setBackgroundColor (int r, int g, int b, int a)
 set the window's background color. More...
 
static int getTime ()
 get the time in milliseconds. More...
 
static string getOS ()
 get the operating system. More...
 
static bool isMobile ()
 get whether or not the OS is mobile. More...
 
static bool isStatic ()
 gets whether or not the client is able to change worlds. More...
 
static game addError (string err)
 adds an error to be displayed. More...
 
static game setTimeout (int milliseconds, string func="",...)
 sets a timer (in milliseconds) that is triggered when the time is up. More...
 
static game removeTimeouts (string func="*", string script=script:thisName())
 removes one or more timers started by the matching script with the matching function name. More...
 
static game removeTimeouts (function func)
 removes one or more timers started by this script that calls the given function. More...
 
static element getFocusedElement ()
 gets the focused element. More...
 
static vector< vector< vector< int > > > getImagePixels (string imagePath, int x=0, int y=0, int w=-1, int h=-1)
 gets a list of all pixel colors from an image. More...
 
static game openLink (string URL, bool newTab=true)
 opens a link by URL. More...
 
static game pushState (function func,...)
 pushes a new state onto the state stack. More...
 
static multiReturn< int, int > getDPI ()
 gets the number of dots per inch on the screen. More...
 
static game draw2dline (int startX, int startY, int endX, int endY, int r=255, int g=255, int b=255, int a=255)
 draws a 2d line. More...
 
static bool isKeyDown (string key)
 checks if the given key is currently down or not. More...
 

Detailed Description

the game program/application.

Member Function Documentation

◆ addError()

static game game::addError ( string  err)
static

adds an error to be displayed.

   Adds an error to an error list to be displayed.\n
   If the error is already in the error list,
   then it is not added.
Parameters
Theerror message to be displayed.
Returns
Returns itself.

◆ draw2dline()

static game game::draw2dline ( int  startX,
int  startY,
int  endX,
int  endY,
int  r = 255,
int  g = 255,
int  b = 255,
int  a = 255 
)
static

draws a 2d line.

Parameters
Thestarting X of the line.
Thestarting Y of the line.
Theending X of the line.
Theending Y of the line.
(optional)The amount of red (0-255).
(optional)The amount of green (0-255).
(optional)The amount of blue (0-255).
(optional)The amount of alpha (transparency) (0-255).
Returns
Returns itself.

◆ drawRectangle()

static game game::drawRectangle ( int  x,
int  y,
int  width = 100,
int  height = 50,
bool  border = false,
int  r = 0,
int  g = 0,
int  b = 0,
int  a = 255,
int  clipX = 0,
int  clipY = 0,
int  clipWidth = game:getWindowWidth(),
int  clipHeight = game:getWindowHeight() 
)
static

draw a rectangle onto the screen.

Parameters
TheX axis of the rectangle.
TheY axis of the rectangle.
(optional)The width of the rectangle.
(optional)The height of the rectangle.
(optional)Whether the rectangle is only the border or filled.
(optional)The amount of red (0-255).
(optional)The amount of green (0-255).
(optional)The amount of blue (0-255).
(optional)The amount of alpha (transparency) (0-255).
(optional)The clipping X (the rectangle will not draw pixels lower than the clipping X).
(optional)The clipping Y.
(optional)The clipping width (the rectangle will not draw pixels above the clipping X + the clipping width).
(optional)The clipping height.
Returns
Returns itself.

◆ getDPI()

static multiReturn<int, int> game::getDPI ( )
static

gets the number of dots per inch on the screen.

   Converts an inch to pixels and returns the horizontal (X) and vertical (Y) dots per inch.

◆ getElementFromID()

static element* game::getElementFromID ( string  ID)
static

get a GUI element from an ID.

Parameters
TheGUI element's ID.
Returns
If the element exists, then the element with the given ID. Otherwise, nil.

◆ getElementFromPosition()

static element* game::getElementFromPosition ( int  x,
int  y 
)
static

gets an element from an absolute position.

Parameters
Thex axis of the position.
They axis of the position.
Returns
The element on the top-most layer of the given position. If none, returns nil.

◆ getFocusedElement()

static element game::getFocusedElement ( )
static

gets the focused element.

Returns
The focused element, if any. Otherwise, nil.

◆ getImagePixels()

static vector<vector<vector<int> > > game::getImagePixels ( string  imagePath,
int  x = 0,
int  y = 0,
int  w = -1,
int  h = -1 
)
static

gets a list of all pixel colors from an image.

   Gets all pixel colors from an image or part of an image.\n
   The returned variable looks something like, for example:\n
   \t { { { 255, 255, 255, 255 }, { 0, 0, 0, 0 }, ... }, ... }\n
   Where the numbers represent red, green blue, and alpha respectively.\n
   Returns nil if the image file does not exist or is not yet downloaded.
Parameters
Thepath of the image file.
(optional)The starting X, in pixels, to grab from the image.
(optional)The starting Y, in pixels, to grab from the image.
(optional)The amount of pixels, in width, to grab from the image. If negative, will grab until the end width of the image.
(optional)The amount of pixels, in height, to grab from the image. If negative, will grab until the end height of the image.
Returns
A 2D array of an array of pixel colors.

◆ getMeshFromID()

static mesh* game::getMeshFromID ( string  ID)
static

get a mesh from an ID.

Parameters
Themesh's ID.
Returns
If the mesh exists, then the mesh with the given ID. Otherwise, nil.

◆ getOpenFileName()

static game game::getOpenFileName ( function  func,
  ... 
)
static

get a selected file from the operating system's file browser.

   Opens the operating system's default file browser to select a file.
   Calls the given function upon file selection.
Parameters
Thefunction to trigger with the server response.
(optional)Any number of values to pass to the function, func, when invoked.
Returns
Returns itself.

◆ getOS()

static string game::getOS ( )
static

get the operating system.

   Get which operating system the user is running.
   Currently only "Windows", "Android", "iOS", and "Web" are supported.
Returns
The user's operating system.

◆ getSaveFileName()

static game game::getSaveFileName ( function  func,
  ... 
)
static

choose a file location to save using the operating system's file browser.

   Opens the operating system's default file browser to save a file.
   Calls the given function upon file selection.
Parameters
Thefunction to trigger with the server response.
(optional)Any number of values to pass to the function, func, when invoked.
Returns
Returns itself.

◆ getScript()

static string game::getScript ( string  filePath)
static

get the code to the script with the given file path.

   Get the content of a running script. If the script is not loaded but it is saved locally, gets the contents of the script file.
  If the script doesn't exist, returns nil.
Parameters
thescript's file path.
Returns
the content of a running script, if it exists. Otherwise, nil.

◆ getScripts()

static string [] game::getScripts ( string  folder = "",
string  filter = "" 
)
static

get a table of all running script names.

   Get a table list of all running scripts, filtered if a filter is given and in a folder if a folder path is given.
   If there are no scripts, returns nil.
Returns
a table list of script names, if any. Otherwise, nil.

◆ getTime()

static int game::getTime ( )
static

get the time in milliseconds.

Returns
The time in milliseconds.

◆ getWindowHeight()

static int game::getWindowHeight ( bool  dpiAware = true)
static

get the window's height.

Parameters
Whetheror not the return value is based on DPI.
Returns
The window's height.

◆ getWindowWidth()

static int game::getWindowWidth ( bool  dpiAware = true)
static

get the window's width.

Parameters
Whetheror not the return value is based on DPI.
Returns
The window's width.

◆ getWindowX()

static int game::getWindowX ( bool  dpiAware = true)
static

get the window's x.

Parameters
Whetheror not the return value is based on DPI.
Returns
The window's x.

◆ getWindowY()

static int game::getWindowY ( bool  dpiAware = true)
static

get the window's y.

Parameters
Whetheror not the return value is based on DPI.
Returns
The window's y.

◆ isKeyDown()

static bool game::isKeyDown ( string  key)
static

checks if the given key is currently down or not.

   Gets whether or not the key is currently being held down.\n
   WARNING: This is different than adding a key event (see: game:addEventListener(Event.Game.onKeyDown) and game:addEventListener(Event.Game.onKeyUp)), as this checks at the time that keyIsDown is called.
Parameters
Thekey to check if it is currently down.
Returns
Whether or not the given key is down.

◆ isMobile()

static bool game::isMobile ( )
static

get whether or not the OS is mobile.

Returns
If the OS is mobile, return true, otherwise false.

◆ isStatic()

static bool game::isStatic ( )
static

gets whether or not the client is able to change worlds.

   A game is static if, upon joining the app, the user did not go through
   the login screen but instead directly went to a world.
Returns

◆ loadScripts()

static game game::loadScripts ( string  filePath)
static

load a script or scripts in a directory.

   Load a script with the given file path. If the path ends with a slash ('/'),
   then load all scripts in the folder directory.
Parameters
Thescript file path or the directory that contains one or more scripts.
Returns
Returns itself.

◆ openLink()

static game game::openLink ( string  URL,
bool  newTab = true 
)
static

opens a link by URL.

   Opens the given URL in the default system browser.\n
   Allows the option to open the link in a new tab or the same window, only if the client is on the web version.
Parameters
TheURL to open.
(optional)Whether or not the link should open in a new tab. Only usable on web.
Returns
Returns itself.

◆ pushState()

static game game::pushState ( function  func,
  ... 
)
static

pushes a new state onto the state stack.

   Adds a state. States are used for the back/forward arrows on web browsers or mobile devices (such as Android).\n
   When the state is changed, the given function is triggered.
Parameters
TheID to identify the state.
Returns
Returns itself.

◆ reload()

static game game::reload ( )
static

reload all scripts.

   Reloads all scripts, starting at onCreated().
   All elements and objects are also reset.
Returns
Returns itself.

◆ removeTimeouts() [1/2]

static game game::removeTimeouts ( function  func)
static

removes one or more timers started by this script that calls the given function.

   Removes a timer set with game:setTimeout() that matches the given function.\n
   Removed timers will no longer be triggered in the script(s). Only removes timers started in this script.
Parameters
Removes(a) timeout(s) that trigger the given function.
Returns
Returns itself.

◆ removeTimeouts() [2/2]

static game game::removeTimeouts ( string  func = "*",
string  script = script:thisName() 
)
static

removes one or more timers started by the matching script with the matching function name.

   Removes a timer set with game:setTimeout() that matches the given function name.\n
   You may use an asterisk (*) to match multiple timeouts.\n
   Removed timers will no longer be triggered in the script(s). Only removes timers started in the script(s) that match the given script name.
Parameters
(optional)Removes (a) timeout(s) that match the given function name. If no function is given, all timers will be cleared.
(optional)Removes the timeout(s) from the scripts matching the given script name. If no script name given, only removes from the current script.
Returns
Returns itself.

◆ scriptLoaded()

static bool game::scriptLoaded ( string  filePath)
static

checks whether or not the script has loaded.

   If the script has been loaded, returns true. Otherwise, returns false.
   NOTE: loaded means that the script has been loaded using loadScripts(), and that it has successfully downloaded
   from the server and ran it's onCreated() function.
Returns
Whether or not the script has loaded.

◆ setBackgroundColor()

static game game::setBackgroundColor ( int  r,
int  g,
int  b,
int  a 
)
static

set the window's background color.

Parameters
Theamount of red (0-255).
Theamount of green (0-255).
Theamount of blue (0-255).
Theamount of alpha (transparency) (0-255).
Returns
Returns itself.

◆ setKeyDown()

static game game::setKeyDown ( string  key)
static

set a key down.

Parameters
Thekey to set as down.
Returns
Returns itself.

◆ setScript()

static game game::setScript ( string  filePath,
string  code,
bool  remove = false 
)
static

set the code of the script with the given file path.

Parameters
Thescript's file path to set the code to.
Thenew code to the given script.
(optional)Whether or not the script should be entirely removed and re-created or not (if not, just clears the script and re-runs).
Returns
Returns itself.

◆ setTimeout()

static game game::setTimeout ( int  milliseconds,
string  func = "",
  ... 
)
static

sets a timer (in milliseconds) that is triggered when the time is up.

   Sets a timer for the given amount of time.\n
   After the time has passed and no function, func, was given, function onTimeout() is triggered. If func was given, the function, func, is called with the given params (if any). See Events for additional params that are passed.
Parameters
Theamount of time in milliseconds until onTimeout() is called.
(optional)The function to be triggered after the given time has passed. If no function given, onTimeout() is called.
(optional)Any number of arguments to be passed to the function.
Returns
Returns itself.

◆ setTitle()

static game game::setTitle ( string  title = "")
static

sets the window title.

Parameters
(optional)The title to set. Leave blank to use the default title.
Returns
Returns itself.