Psych Engine Logo
Psych Engine - Lua Script API

Reflection Functions

Functions to get/set properties from (both Hardcoded and Lua) Objects and call their methods.


getProperty

getProperty(variable:String, ?allowMaps:Bool = false):Dynamic

Returns the value of a property or variable inside PlayState, a variable saved through "setVar" or a Lua Sprite/Text.

Examples:


getPropertyFromGroup

getPropertyFromGroup(variable:String, index:Int, property:Dynamic, ?allowMaps:Bool = false):Dynamic

Returns the value of a property of a member inside a FlxTypedGroup/FlxSpriteGroup.

Examples:


getPropertyFromClass

getPropertyFromClass(classVar:String, variable:String, ?allowMaps:Bool = false):Dynamic

Returns the value of a property inside a class.

Examples:


setProperty

setProperty(variable:String, value:Dynamic, ?allowMaps:Bool = false, ?allowInstances:Bool = false):Dynamic

Sets the value of a property or variable inside PlayState, a variable saved through "setVar" or a Lua Sprite/Text.
Returns "value".

Examples:


setPropertyFromGroup

setPropertyFromGroup(variable:String, index:Int, property:Dynamic, value:Dynamic, ?allowMaps:Bool = false, ?allowInstances:Bool = false):Dynamic

Sets the value of a property of a member inside a FlxTypedGroup/FlxSpriteGroup.
Returns "value".

Examples:


setPropertyFromClass

setPropertyFromClass(classVar:String, variable:String, value:Dynamic, ?allowMaps:Bool = false, ?allowInstances:Bool = false):Dynamic

Sets the value of a property inside a class.
Returns "value".

Examples:


callMethod

callMethod(funcToRun:String, ?args:Array<Dynamic> = null):Dynamic

Calls a function and returns its value.

Examples:


callMethodFromClass

callMethodFromClass(classVar:String, funcToRun:String, ?args:Array<Dynamic> = null):Dynamic

Calls a function inside a Class and returns its value.

Examples:


instanceArg

instanceArg(instanceName:String, ?classVar:String = null):String

Meant to be used with "callMethod", "callMethodFromClass", "createInstance", "setProperty", "setPropertyFromGroup", "setPropertyFromClass" and "setVar".
Formats a String in a specific way to tell the previously mentioned functions that the string is meant to be an instance.

Examples:


createInstance

createInstance(variableToSave:String, classVar:String, ?args:Array<Dynamic> = null):Bool

Creates an instance of a Class and saves it to a lua variable nametag that allows you to use setProperty and other functions on it.
Returns "true" or "false" for if it was created successfully.

Examples:

Note: In most cases you still have to add the created instance with "addInstance".


addInstance

addInstance(objectName:String, ?inFront:Bool = false):Void

Adds the instance to the scene.

Examples:

Note: As of 1.0, this function is redundant as it does nearly the same thing as "addLuaSprite"


getObjectOrder

getObjectOrder(tag:String, ?group:String = null):Int

Returns the object layer in the Scene or inside a group.
Throws an error and returns -1 if the object or group couldn't be found.

Examples:


setObjectOrder

setObjectOrder(tag:String, position:Int, ?group:String = null):Void

Sets the object layer in the Scene or inside a group.

Examples:


addToGroup

addToGroup(group:String, tag:String, ?index:Int = -1):Void

Adds the object to a group.

Examples:


removeFromGroup

removeFromGroup(group:String, ?index:Int = -1, ?tag:String = null, ?destroy:Bool = true):Void

Adds the object to a group.

Examples:


setObjectCamera

setObjectCamera(tag:String, ?camera:String = 'game'):Bool

Changes the Object's Draw Camera.
Returns if the operation was successful.

Examples:


setScrollFactor

setScrollFactor(tag:String, scrollX:Float, scrollY:Float):Void

Changes the parallax of an Object.

Examples:


screenCenter

screenCenter(tag:String, ?axis:String = 'xy'):Void

Centers an Object to the Screen on the specified axis.

Examples:


scaleObject

scaleObject(tag:String, x:Float, y:Float, ?updateHitbox:Bool = true):Void

Scales an Object by a ratio.

Examples:


setGraphicSize

setGraphicSize(tag:String, x:Float, ?y:Float = 0, ?updateHitbox:Bool = true):Void

Scales an Object by a ratio.

Examples:


updateHitbox

updateHitbox(tag:String):Void

Updates the Width/Height hitboxes and the Offset of an Object, used after scaling operations.


setBlendMode

setBlendMode(tag:String, ?blend:String = ''):Bool

Changes the Blend Mode of an object, similarly to Photoshop and other image editors.
Returns if the operation was successful.

Examples:

Note: Some blend modes like "OVERLAY" just seem to not work at all, this is not my fault!


getMidpointX

getMidpointX(tag:String):Float

Returns the X of the center point of an Object.


getMidpointY

getMidpointY(tag:String):Float

Returns the Y of the center point of an Object.


getGraphicMidpointX

getGraphicMidpointX(tag:String):Float

Returns the Object's Graphic center X.


getGraphicMidpointY

getGraphicMidpointY(tag:String):Float

Returns the Object's Graphic center Y.


getScreenPositionX

getScreenPositionX(tag:String, ?camera:String = 'game'):Float

Returns the Object's On-Camera X Position.

Examples:


getScreenPositionY

getScreenPositionY(tag:String, ?camera:String = 'game'):Float

Returns the Object's On-Camera Y Position.

Examples:


getPixelColor

getPixelColor(tag:String, x:Int, y:Int):Int

Gets the color of a pixel in a Sprite's Graphic.
Returns the color's integer value, if invalid, it returns black.

Note: Sprites will require to have their GPU Caching turned off for it to work.


objectsOverlap

objectsOverlap(obj1:String, obj2:String):Bool

Returns if two Object hitboxes are overlapping each other, useful for collision checking.

Examples: