string join(string[], string delimiter)
Joins the contents of the given array into a single string, separated by the given delimiter

float cos(float)
Returns the cosine of the angle given in radians.

float sin(float)
Returns the sine of the angle given in radians.

float tan(float)
Returns the tangent of the angle given in radians.

float acos(float)
Returns the arc sine in radians of the given value.

float asin(float)
Returns the arc cosine in radians of the given value.

float atan(float)
Returns the arc tangent in radians of the given value.

float atan2(float x, float y)
Returns the angle in radians between the given vector and the vector (1,0)

float cosh(float)
Returns the hyperbolic cosine of the given value in radians.

float sinh(float)
Returns the hyperbolic sine of the given value in radians.

float tanh(float)
Returns the hyperbolic tangent of the given value in radians.

float log(float)
Returns the base e logarithm of the given value.

float log10(float)
Returns the base 10 logarithm of the given value.

float pow(float a, float b)
Returns a raised to the power of b.

float sqrt(float)
Returns the square root of the given value.

float ceil(float)
Returns the 'ceiling' of the given value (round up to closest integer).

float abs(float)
Returns the absolute value of the given value.

float floor(float)
Returns the 'floor' of the given value (round down to closest integer).

float fraction(float)
Returns the signed fractional part of a floating point number, eg. fraction(-12.34) = -0.34

float rnd()
Returns a random number between 0 and 1.

float dr(float)
Converts an angle from degrees to radians.

float rd(float)
Converts an angle from radians to degrees.

vec2 cursor()
Returns the current position of the cursor.

vec2 getCursor()
Returns the current position of the cursor.

void setCursor(float x, float y)
Sets the position of the cursor.

void setCursor(vec2)
Sets the position of the cursor.

vec2 getGravity()
Returns the gravity vector of the world.

void setGravity(float, float)
Sets the gravity of the world.

void setGravity(vec2)
Sets the gravity of the world.

void setSimulationStepsPerSecond(float)
Sets the simulation steps per second of the world.

void setSimulationPositionIterations(int)
Sets the number of position iterations to perform per simulation step.

void setSimulationVelocityIterations(int)
Sets the number of velocity iterations to perform per simulation step.

body getBody(int)
Returns the body in the scene with the given id. If the body does not exist, an invalid body will be returned.

body getBody(string)
Returns the first body in the scene with the given name. If the body does not exist, an invalid body will be returned.

body[] getBodies(string)
Returns a list of all bodies in the scene with the given name.

body[] getSelectedBodies()
Returns a list of all selected bodies in the scene.

body[] sb()
Shortcut for getSelectedBodies. Returns a list of all selected bodies in the scene.

body[] getAllBodies()
Returns a list of all bodies in the scene.

body[] ab()
Shortcut for getAllBodies. Returns a list of all bodies in the scene.

body addBody(int bodyId, string bodyDefinition)
Adds a body with the given id to the scene. The features of the body will be taken from the specified JSON string. If the given id is -1, the next available id will be used. If the given id is not -1 and is already in use, the next available id will be used and a warning will be printed to the console.

void select(body[])
Selects all bodies in the given list.

void deselect(body[])
Deselects all bodies in the given list.

void delete(body[])
Deletes all bodies in the given list.

vertex getVertex(int fixtureId, int vertexIndex)
Returns the vertex of the given index belonging to the fixture of the given id. If the vertex does not exist, an invalid vertex will be returned.

vertex getVertex(string fixtureName, int vertexIndex)
Returns the vertex of the given index belonging to the first fixture of the given name. If the vertex does not exist, an invalid vertex will be returned.

vertex[] getVertices(string)
Returns a list of all vertices belonging to all fixtures with the given name.

vertex[] getSelectedVertices()
Returns a list of all selected vertices in the scene.

vertex[] sv()
Shortcut for getSelectedVertices. Returns a list of all selected vertices in the scene.

vertex[] getAllVertices()
Returns a list of all vertices in the scene.

vertex[] av()
Shortcut for getVertices. Returns a list of all vertices in the scene.

void select(vertex[])
Selects all vertices in the given list.

void deselect(vertex[])
Deselects all vertices in the given list.

void delete(vertex[])
Deletes all vertices in the given list.

fixture getFixture(int)
Returns the fixture in the scene with the given id. If the fixture does not exist, an invalid fixture will be returned.

fixture getFixture(string)
Returns the first fixture in the scene with the given name. If the fixture does not exist, an invalid fixture will be returned.

fixture[] getFixtures(string)
Returns a list of all fixtures in the scene with the given name.

fixture[] getSelectedFixtures()
Returns a list of all selected fixtures in the scene.

fixture[] sf()
Shortcut for getSelectedFixtures. Returns a list of all selected fixtures in the scene.

fixture[] getAllFixtures()
Returns a list of all fixtures in the scene.

fixture[] af()
Shortcut for getAllFixtures. Returns a list of all fixtures in the scene.

void select(fixture[])
Selects all fixtures in the given list.

void deselect(fixture[])
Deselects all fixtures in the given list.

void delete(fixture[])
Deletes all fixtures in the given list.

joint getJoint(int)
Returns the joint in the scene with the given id. If the joint does not exist, an invalid joint will be returned.

joint getJoint(string)
Returns the first joint in the scene with the given name. If the joint does not exist, an invalid joint will be returned.

joint[] getJoints(string)
Returns a list of all joints in the scene with the given name.

joint[] getSelectedJoints()
Returns a list of all selected joints in the scene.

joint[] sj()
Shortcut for getSelectedJoints. Returns a list of all selected joints in the scene.

joint[] getAllJoints()
Returns a list of all joints in the scene.

joint[] aj()
Shortcut for getAllJoints. Returns a list of all joints in the scene.

joint addJoint(int jointId, string jointDefinition)
Adds a joint with the given id to the scene. The bodyA, bodyB and other features of the joint will be taken from the specified JSON string. If the given id is -1, the next available id will be used. If the given id is not -1 and is already in use, the next available id will be used and a warning will be printed to the console.

void select(joint[])
Selects all joints in the given list.

void deselect(joint[])
Deselects all joints in the given list.

void delete(joint[])
Deletes all joints in the given list.

shape getShape(int, int)
Returns the shape of the given index belonging to the fixture of the given id. If the shape does not exist, an invalid shape will be returned.

image getImage(int)
Returns the first image in the scene with the given id. If the image does not exist, an invalid image will be returned.

image getImage(string)
Returns the first image in the scene with the given name. If the image does not exist, an invalid image will be returned.

image[] getImages(string)
Returns a list of all images in the scene with the given name.

image[] getSelectedImages()
Returns a list of all selected images in the scene.

image[] si()
Shortcut for getSelectedImages. Returns a list of all selected images in the scene.

image[] getAllImages()
Returns a list of all images in the scene.

image[] ai()
Shortcut for getAllImages. Returns a list of all images in the scene.

image addImage(int imageId, string imageDefinition)
Adds an image with the given id to the scene. The features of the image will be taken from the specified JSON string. If the given id is -1, the next available id will be used. If the given id is not -1 and is already in use, the next available id will be used and a warning will be printed to the console.

image addImage(string imageFile, vec2 center)
Adds an image to the scene. The image will be loaded from the specified file and placed at the specified location.

void select(image[])
Selects all images in the given list.

void deselect(image[])
Deselects all images in the given list.

void delete(image[])
Deletes all images in the given list.

world getWorld()
Returns a reference to the world.

void print(string)
Prints out a message to the script console (at the bottom of the 'Script' docking panel). This can be useful for debugging scripts.

void print(int)
Prints the given integer to the script console.

void print(bool)
Prints the given boolean to the script console.

void print(float)
Prints the given float to the script console.

void print(vec2)
Prints the given vec2 to the script console.

void print(color)
Prints the RGBA components of the given color to the script console separated by commas. Printed values will be between 0 and 1. Try these functions for other representations: color::getStr255(), color::getStrHex()

void print(body)
Prints the name and id of the given body to the script console.

void print(fixture)
Prints the name and id of the given fixture to the script console.

void print(vertex)
Prints the name and id of the given vertex to the script console.

void print(joint)
Prints the name and id of the given joint to the script console.

void print(image)
Prints the name and id of the given image to the script console.

void print(vec2[])
Prints each vec2 in the array to the script console.

void print(body[])
Prints each body in the array to the script console.

void print(fixture[])
Prints each fixture in the array to the script console.

void print(vertex[])
Prints each vertex in the array to the script console.

void print(joint[])
Prints each joint in the array to the script console.

void print(image[])
Prints each image in the array to the script console.

void print(string[])
Prints each string in the array to the script console.

int intval(string)
Returns the integer value of the given string, or zero if the string could not be converted to an integer.

int intval(string, bool& ok)
Returns the integer value of the given string, or zero if the string could not be converted to an integer. On return, the variable ok will be set to true if the conversion succeeded.

float floatval(string)
Returns the float value of the given string, or zero if the string could not be converted to an float.

float floatval(string, bool& ok)
Returns the float value of the given string, or zero if the string could not be converted to an float. On return, the variable ok will be set to true if the conversion succeeded.

vec2 getMousePos()
Returns the last reported position of the mouse pointer, as shown in the status bar of the application.

string queryOpenFile(string filter)
Executes a file open dialog to allow the user to select an existing file. This function returns the full filepath of the selected file, or an empty string if the selection was canceled.

The filter string can be used to specify what type of files should be chosen, eg. to limit the selection to PNG files the filter

"PNG files (*.png)"

would be given. The first part of this filter string is merely a label and is not necessary, while the second part (in parenthesis) is the actual filter. Multiple filters can be given, separated by two semi-colons. Multiple file extensions for one filter can be given, separated by a space. Eg. this filter allows the user to choose from a list of PNG/BMP files, or each file type separately:

"Usable files (*.png *.bmp);;PNG files (*.png);;BMP files (*.bmp)"

float queryNumericValue(string description)
Executes a simple dialog to allow the user to enter a number. The 'description' parameter will be shown in the dialog to let the user know what the number is for. This function will return the numerical value the user entered. If no number is entered or the user closes the dialog by pressing the ESC key, this function will return zero.

float queryNumericValue(string description, float defaultValue)
Executes a simple dialog to allow the user to enter a number. The 'description' parameter will be shown in the dialog to let the user know what the number is for. The initial value in the text entry field can be set with the 'defaultValue' parameter. This function will return the numerical value the user entered. If no number is entered or the user closes the dialog by pressing the ESC key, this function will return zero.

vec2 queryVectorValue(string description)
Executes a simple dialog to allow the user to enter a vector location. The 'description' parameter will be shown in the dialog to let the user know what the vector is for. This function will return the value the user entered. If the user closes the dialog by pressing the ESC key, this function will return the vector (0,0).

vec2 queryVectorValue(string description, float defaultX, float defaultY)
Executes a simple dialog to allow the user to enter a vector location. The 'description' parameter will be shown in the dialog to let the user know what the vector is for. The initial value in the text entry field can be set with the 'defaultX' and 'defaultY' parameters. This function will return the value the user entered. If the user closes the dialog by pressing the ESC key, this function will return the vector (0,0).

string queryStringValue(string description)
Executes a simple dialog to allow the user to enter a text string. The 'description' parameter will be shown in the dialog to let the user know what the string is for. This function will return the text value the user entered. If no text is entered or the user closes the dialog by pressing the ESC key, this function will return an empty string.

string queryStringValue(string description, string defaultValue)
Executes a simple dialog to allow the user to enter a text string. The 'description' parameter will be shown in the dialog to let the user know what the string is for. The initial value in the text entry field can be set with the 'defaultValue' parameter. This function will return the text value the user entered. If no text is entered or the user closes the dialog by pressing the ESC key, this function will return an empty string.

bool queryYesNo(string description)
Executes a simple dialog to allow the user to reply Yes or No. The 'description' parameter will be shown in the dialog to let the user know what the question is about. If the user closes the dialog by pressing the ESC key, this function will return false.

string getSupportedImageFormatsFilter()
Returns a string containing currently supported image file formats for use with the queryOpenFile function.

string getCurrentActionMenuFolder()
When the script is being executed from the action menu, this function will return the name of the sub-folder under config/actionMenu in which the script .rs file resides, otherwise it returns empty string.

body duplicate(body)
Creates a duplicate of the given body and returns a reference to it.

body duplicate(body, bool createJoints)
Creates a duplicate of the given body and returns a reference to it. The second parameter specifies whether to also duplicate any joints the body has.

fixture duplicate(fixture)
Creates a duplicate of the given fixture and returns a reference to it.

joint duplicate(joint)
Creates a duplicate of the given joint and returns a reference to it.

image duplicate(image)
Creates a duplicate of the given image and returns a reference to it.

body[] duplicate(body[])
Creates duplicates of all bodies in the list and returns a list containing the new items.

body[] duplicate(body[], bool createJoints)
Creates duplicates of all bodies in the list and returns a list containing the new items. The second parameter specifies whether to also duplicate any joints the body has.

fixture[] duplicate(fixture[])
Creates duplicates of all fixtures in the list and returns a list containing the new items.

joint[] duplicate(joint[])
Creates duplicates of all joints in the list and returns a list containing the new items.

image[] duplicate(image[])
Creates duplicates of all images in the list and returns a list containing the new items.

void translate(body, vec2)
Translates the body by the given distance.

void translate(fixture, vec2)
Translates the fixture by the given distance.

void translate(joint, int whichAnchor, vec2)
Translates the joint anchor(s) by the given distance. The second parameter is a bit flag to specify which anchor should be moved. Use 1 for anchorA, 2 for anchorB, or 3 for both.

void translate(image, vec2)
Translates the image by the given distance.

void translate(vertex, vec2)
Translates the vertex by the given distance.

void translate(body, float x, float y)
Translates the body by the given distance.

void translate(fixture, float x, float y)
Translates the fixture by the given distance.

void translate(joint, int whichAnchor, float x, float y)
Translates the joint anchor(s) by the given distance. The second parameter is a bit flag to specify which anchor should be moved. Use 1 for anchorA, 2 for anchorB, or 3 for both.

void translate(image, float x, float y)
Translates the image by the given distance.

void translate(vertex, float x, float y)
Translates the vertex by the given distance.

void translate(body[], vec2)
Translates all bodies in the list by the given distance. The return value is the original list.

void translate(fixture[], vec2)
Translates all fixtures in the list by the given distance. The return value is the original list.

void translate(joint[], int whichAnchor, vec2)
Translates the joint anchor(s) of all joints in the list by the given distance. The second parameter is a bit flag to specify which anchors should be moved - use 1 for anchorA, 2 for anchorB, or 3 for both. The return value is the original list.

void translate(image[], vec2)
Translates all images in the list by the given distance. The return value is the original list.

void translate(vertex[], vec2)
Translates all vertices in the list by the given distance. The return value is the original list.

void translate(body[], float x, float y)
Translates all bodies in the list by the given distance. The return value is the original list.

void translate(fixture[], float x, float y)
Translates all fixtures in the list by the given distance. The return value is the original list.

void translate(joint[], int whichAnchor, float x, float y)
Translates the joint anchor(s) of all joints in the list by the given distance. The second parameter is a bit flag to specify which anchors should be moved - use 1 for anchorA, 2 for anchorB, or 3 for both. The return value is the original list.

void translate(image[], float x, float y)
Translates all images in the list by the given distance. The return value is the original list.

void translate(vertex[], float x, float y)
Translates all vertices in the list by the given distance. The return value is the original list.

void rotate(body, int whichCenter, float angle)
Rotates the body by the given angle (radians). The second parameter specifies whether to rotate around the cursor (0) or the selection center (1).

void rotate(fixture, int whichCenter, float angle)
Rotates the fixture by the given angle (radians). The second parameter specifies whether to rotate around the cursor (0) or the selection center (1).

void rotate(joint, int whichAnchor, int whichCenter, float angle)
Rotates the joint by the given angle (radians). The second parameter is a bit flag to specify which anchors should be moved - use 1 for anchorA, 2 for anchorB, or 3 for both. The third parameter specifies whether to rotate around the cursor (0) or the selection center (1).

void rotate(image, int whichCenter, float angle)
Rotates the image by the given angle (radians). The second parameter specifies whether to rotate around the cursor (0) or the selection center (1).

void rotate(vertex, int whichCenter, float angle)
Rotates the vertex by the given angle (radians). The second parameter specifies whether to rotate around the cursor (0) or the selection center (1).

void rotate(body[], int whichCenter, float angle)
Rotates all bodies in the list by the given angle (radians). The second parameter specifies whether to rotate around the cursor (0) or the selection center (1).

void rotate(fixture[], int whichCenter, float angle)
Rotates all fixtures in the list by the given angle (radians). The second parameter specifies whether to rotate around the cursor (0) or the selection center (1).

void rotate(joint[], int whichAnchor, int whichCenter, float angle)
Rotates all joints in the list by the given angle (radians). The second parameter is a bit flag to specify which anchors should be moved - use 1 for anchorA, 2 for anchorB, or 3 for both. The third parameter specifies whether to rotate around the cursor (0) or the selection center (1).

void rotate(image[], int whichCenter, float angle)
Rotates all images in the list by the given angle (radians). The second parameter specifies whether to rotate around the cursor (0) or the selection center (1).

void rotate(vertex[], int whichCenter, float angle)
Rotates all vertices in the list by the given angle (radians). The second parameter specifies whether to rotate around the cursor (0) or the selection center (1).

body[] sortBodies(body[], bodySortFunc@)
Sorts the bodies in the list according to the provided comparison function and returns the sorted list (the original list is not changed). The comparison function should be of the form: bool myfunction(body, body) and should return true if the parameters are in the correct order.

body[] filterBodies(body[], bodyFilterFunc@)
Filters the bodies in the list according to the provided filter function and returns the filtered list (the original list is not changed). The filter function should be of the form: bool myfunction(body) and should return true if the item should remain in the result list.

fixture[] sortFixtures(fixture[], fixtureSortFunc@)
Sorts the fixtures in the list according to the provided comparison function and returns the sorted list (the original list is not changed). The comparison function should be of the form: bool myfunction(fixture, fixture) and should return true if the parameters are in the correct order.

fixture[] filterFixtures(fixture[], fixtureFilterFunc@)
Filters the fixtures in the list according to the provided filter function and returns the filtered list (the original list is not changed). The filter function should be of the form: bool myfunction(fixture) and should return true if the item should remain in the result list.

joint[] sortJoints(joint[], jointSortFunc@)
Sorts the joints in the list according to the provided comparison function and returns the sorted list (the original list is not changed). The comparison function should be of the form: bool myfunction(joint, joint) and should return true if the parameters are in the correct order.

joint[] filterJoints(joint[], jointFilterFunc@)
Filters the joints in the list according to the provided filter function and returns the filtered list (the original list is not changed). The filter function should be of the form: bool myfunction(joint) and should return true if the item should remain in the result list.

image[] sortImages(image[], imageSortFunc@)
Sorts the images in the list according to the provided comparison function and returns the sorted list (the original list is not changed). The comparison function should be of the form: bool myfunction(image, image) and should return true if the parameters are in the correct order.

image[] filterImages(image[], imageFilterFunc@)
Filters the images in the list according to the provided filter function and returns the filtered list (the original list is not changed). The filter function should be of the form: bool myfunction(image) and should return true if the item should remain in the result list.

vertex[] sortVertices(vertex[], vertexSortFunc@)
Sorts the vertices in the list according to the provided comparison function and returns the sorted list (the original list is not changed). The comparison function should be of the form: bool myfunction(vertex, vertex) and should return true if the parameters are in the correct order.

vertex[] filterVertices(vertex[], vertexFilterFunc@)
Filters the vertices in the list according to the provided filter function and returns the filtered list (the original list is not changed). The filter function should be of the form: bool myfunction(vertex) and should return true if the item should remain in the result list.

bool addCustomProperty(string class, string name, string displayName, string type)
Adds a custom property to the specified class. Class must be one of world, body, fixture, joint or image. Type must be one of int, float, string, vec2 or bool. Name must be suitable for use as a variable in source code (alphanumeric or underbar characters only, first character cannot be a number). Display name will be shown in the property panel to identify the property. This function can fail if the property already exists, or if the name is unsuitable.

bool removeCustomProperty(string class, string name)
Removes the named custom property from the specified class.

bool setCustomPropertyNames(string class, string name, string newName, string newDisplayName)
Changes the name and display name of an existing custom property. The first two parameters identify the property to be changed. The last two parameters specify the new names.

string[] getCustomProperties(string class)
Returns a list of the names of all custom properties in a class. Class should be one of world, body, fixture, joint or image.

void setCollisionBitplaneName(int, string)
Sets the name of the specified collision bitplane. Bitplane indices start from zero.

string getCollisionBitplaneName(int)
Gets the name of the specified collision bitplane. Bitplane indices start from zero.

string jsonEncode(dictionary)
Returns a string representing the given dictionary as a JSON object. The following types are supported:Note that vec2[] properties are encoded in JSON as two float arrays, one each for x and y components, as expected by RUBE functions which use JSON to construct items in the scene.

vec2 mv(float, float)
'make vector' - a convenience function to create a vec2 easily.

The vec2 class has no constructor so you cannot conveniently create and initialize vec2 variables simultaneously like: setCursor( vec2(1,2) ); Instead you have to do: vec2 v; v.set(1,2); setCursor(v); which is annoying. This function allows you to do: setCursor( mv(1,2) );

color mc1(float red, float green, float blue, float alpha)
'make color' - a convenience function to create a color. This version takes parameters between 0 and 1.

color mc255(int red, int green, int blue, int alpha)
'make color' - a convenience function to create a color. This version takes parameters between 0 and 255.

color mcHex(string)
'make color' - a convenience function to create a color. This version takes a six-character hexadecimal color string as used in HTML, eg. FF0000 for pure red.

bool dirExists(string path)
Returns true if the specified path exists and is a directory. Relative paths will be resolved from the location of the current .rube file.

bool fileExists(string path)
Returns true if the specified path exists and is a file. Relative paths will be resolved from the location of the current .rube file.

string readFile(string file)
Returns contents of the specified file as a string. If the file does not exist or could not be opened, an empty string will be returned.

bool writeFile(string file, string text)
Writes the given text to the specified file, and returns true if the operation was successful.

string getCurrentEditMode()
Returns the current edit mode of the active editor view, or empty string if no editor view is active. This can be one of the following values:

string getHookEventName()
If the current script was triggered by an event hook (eg. keypress event) this function will return the name of the script hook, otherwise it will return an empty string. Hook names can be one of the following values:

bool isCtrlKeyDown()
If the current script was triggered by a keypress hook this function will return true if Ctrl was pressed when the event was triggered, otherwise it will return false.

bool isAltKeyDown()
If the current script was triggered by a keypress hook this function will return true if Alt was pressed when the event was triggered, otherwise it will return false.

image[] getDroppedImages()
If the current script was triggered by the 'Images dropped' hook, this function will return an array containing the images that were loaded, otherwise it will return an empty array.