Helper - AlsoGhostglowDev/Ghost-s-Utilities GitHub Wiki
GhostUtil's backend helper utility used for resolving common problems/tasks.
Intended for developer use.
local helper = require 'ghostutil.backend.helper'extensions: dictionary<string, module> = { }throwError: boolean = truereflect(): moduleReturns the current instance of reflect module if exists.
Returns: The reflect module. nil is returned if it's not found.
─────────────────────────
legacyAvailable(): booleanChecks if the legacy version (<0.7) has Psych Engine functions available.
(Returns true after onCreate is called)
Returns: true if Psych Engine functions are available; always returns true on versions above and 0.7.0.
─────────────────────────
instanceArg(instance: string, ?class: string): stringRefer to bcompat.instanceArg
─────────────────────────
callMethod(method: string, ?args: table<dynamic>): dynamicRefer to bcompat.callMethod
─────────────────────────
callMethodFromClass(class: string, method: string, ?args: table<dynamic>): dynamicRefer to bcompat.callMethodFromClass
─────────────────────────
createInstance(tag: string, className: string, args: table<dynamic>): boolean Refer to bcompat.createInstance
─────────────────────────
addInstance(instance: string, ?front: boolean): voidRefer to bcompat.addInstance
─────────────────────────
setProperty(prop: string, value: dynamic, ?allowMaps: boolean, ?allowInstances: boolean): dynamicRefer to bcompat.setProperty
─────────────────────────
setPropertyFromClass(class: string, prop: string, value: dynamic, ?allowMaps: boolean, ?allowInstances: boolean): dynamicRefer to bcompat.setPropertyFromClass
─────────────────────────
setPropertyFromGroup(group: string, index: string, prop: string, value: dynamic, ?allowMaps: boolean, ?allowInstances: boolean): dynamicRefer to bcompat.setPropertyFromGroup
─────────────────────────
connect(name: string): moduleConnects to an existing or create a new instance of a GhostUtil extension if exists. This action adds the module (extension) to helper.extensions.
Parameters:
-
name: The extension file name inghostutil/extensions/.
Returns: The module object.
─────────────────────────
getCameraFromString(camera: string): string Fetches the camera from the given camera string, also supports custom cameras that's added through createInstance.
Parameters:
-
camera: The camera name.
(Can be shorten like hud, other, etc., except custom cameras)
Warning
GhostUtil might mistake your custom camera as one of Psych's camera if it has the word 'other' or 'hud'. If so, try changing the name to something else. Sorry for the inconvinience.
Returns: The camera name. camGame is returned by default if camera is not found.
─────────────────────────
getType(e: dynamic, ?structOverDict: boolean): stringA more "accurate" Lua's existing type(), being able to detect dictionaries for table types.
Parameters:
-
e: The element to check. -
structOverDict(optional): If it should returnstructinstead ofdictionaryfor dictionary types.
Returns: e's type.
─────────────────────────
serialize(value: dynamic, t: string)Serializes value to the desired type if it were to be written in Haxe. Commonly used for serializing Lua table/dictionary to Haxe's array, anonymous structure or map.
Parameters:
-
value: The value to serialize. -
t: The type ofvalue.
(can be string, array/table, map/dictionary/dict, struct/structure/anonstruct, bool/boolean or function)
Returns: The serialized value. However, if t is invalid, value is returned unchanged.
─────────────────────────
addHaxeLibrary(library: string, ?package: string): voidDoes the same thing as Psych's addHaxeLibrary without triggering Psych Engine >1.0.0 deprecation warning.
Parameters:
-
library: The library name. -
package(optional): The package the library is from, defaults to an empty string.
─────────────────────────
hgetKeys(map: string): table<dynamic>Fetches a map's keys. The map must be in the variables map or in the current PlayState instance (game) itself.
Parameters:
-
map: The map to fetch the keys from.
Returns: map's keys, if exists, fallbacks to an empty table if nil.
─────────────────────────
getKeys(dict: dictionary<t, dynamic>): t Refer to table.getkeys
─────────────────────────
eqAny(val: dynamic, toCheck: table<dynamic>): boolean Checks if val is equal to any values of toCheck.
Parameters:
-
val: The value to check. -
toCheck: The list of values to match withval.
Returns: true if val equals to one of toCheck's values.
─────────────────────────
isInt(number: number): boolean Checks if number is an integer.
Parameters:
-
number: The number to check.
Returns: true if number is an integer.
─────────────────────────
isFloat(number: number): boolean Checks if number is a floating-point number.
(Shortcut to not helper.isInt(number))
Parameters:
-
number: The number to check.
Returns:: true if number is a Float.
─────────────────────────
isDict(tbl: table|dictionary): boolean Refer to table.isdictionary
─────────────────────────
findIndex(tbl: table<dynamic>, el: dynamic): numberRefer to table.indexof
─────────────────────────
findKey(dict: dictionary<t, dynamic>, value: dynamic): t Refer to table.keyof
─────────────────────────
existsFromTable(tbl: table|dictionary, value: dynamic): boolean Refer to table.contains
─────────────────────────
keyExists(dict: dictionary<t, dynamic>, key: t): boolean Refer to table.containskey
─────────────────────────
stringSplit(str: string, del: string): string Similar to Psych's stringSplit but adds support for legacy Psych (<0.7.0) to use a custom split function before onCreate is called.
Information: Refer to string.split
─────────────────────────
ternary(statement: boolean, a: dynamic, b: dynamic): dynamic Simple ternary in Lua.
Parameters:
-
statement: Either true or false. -
a: The return value ifstatementistrue. -
b: The return value ifstatementisfalse
Returns: a is returned if statement is true else, b is returned.
statement and a or b instead?" A: "That 'ternary' is actually just a trick that's widely used in Lua. It can often be faulty when dealing with booleans or nil values, i.e. statement is true but a is nil or false, this causes Lua to fallback to b even though it should be returning a."
─────────────────────────
bound(n: number, min: number, max: number): numberRefer to math.bound
─────────────────────────
rawsetDict(t: dictionary, path: string, value: dynamic): voidRefer to table.rawsetdict
─────────────────────────
rawgetDict(t: dictionary, path: string): dynamicRefer to table.rawgetdict
─────────────────────────
getDictLength(t: dictionary): numberRefer to table.getdictlength
─────────────────────────
pack(value: dynamic, length: number): table<dynamic>Packs value into a table length times.
Parameters:
-
value: The value to pack. -
length: The amount ofvalueshould be packed into the table.
Returns: The packed table.
─────────────────────────
fillTable(tbl: table<dynamic>, value: dynamic, length: number): table<dynamic>Refer to table.fill
─────────────────────────
resolveNilInTable(tbl: table<dynamic>, fallbackValue: dynamic): table<dynamic>Resolves nil values in tbl, replacing them with fallbackValue instead.
(This is an in-place function directly modifying tbl's structure)
Parameters:
-
tbl: The table to resolve. -
fallbackValue: The value to replacenilvalues with.
Returns: The resolved table for chaining.
─────────────────────────
resizeTable(tbl: table<dynamic>, length: number): table<dynamic>Refer to table.resize
─────────────────────────
arrayComprehension(from: number, to: number, fn: number->dynamic): table<dynamic>Refer to table.arraycomp
─────────────────────────
mapComprehension(keys: table<t1>, fn: t1->t2): dictionary<t1, t2>Refer to table.dictcomp
─────────────────────────
resolveAlt(value: t|table<t>, length: number): table<t>Resolves an alternative way for an t-or-table<t> argument.
This was previously used in GhostUtil 2.0 when functions like game.doTweenPosition used to take number and table<number> simultaneously as one of it's values, whereas if the argument were to be a number, it'll make a table<number> with two (which is the length) of those given number, else it'll just stay as the passed table<number>.
Parameters:
-
value: The passed value. Iftable<t>is passed, it will remain unchanged, else it'll create atable<t>containinglengthtimes the passedvalue. -
length: The target length, ignored ifvalueis a table.
Returns: The resolved value.
─────────────────────────
validate(params: table<dynamic>, types: table<string|table<string>>): booleanChecks if the given parameters matches with the given types.
This is used to validate multiple arguments that was passed through a function was given with the correct type by the user.
Parameters:
-
params: Table containing the parameters to check. -
types: Table containing types that should match to the corresponding parameter. Multiple-types are also supported, usetable<string>containing multiple types instead of the normalstring.
Returns: true if all parameters matches their corresponding type.
─────────────────────────
parseObject(obj: string): stringParses the object tag to a referenceable object in Haxe. Checks the object in the current PlayState instance (game), the variables map and "modchart" maps (<1.0.0).
Warning
This function may not be fully accurate, it may fallback to game.object instead.
Parameters:
-
obj: The object name (tag).
Returns: The object reference.
(can be game.object, getVar("object") or game.getLuaObject("object"))
─────────────────────────
concat(t1: table, t2: table): tableRefer to table.merge
─────────────────────────
concatDict(d1: dictionary, d2: dictionary, ?override: boolean): dictionaryRefer to table.mergedict
─────────────────────────
isOfType(value: dynamic, t: string): booleanRefer to util.isOfType
─────────────────────────
resolveDefaultValue(value: dynamic, fallback: dynamic): dynamicResolves for nil values that occurs on default values. This function may only be useful when you're working with booleans, but other than that, value or fallback should be safe to use.
Parameters:
-
value: The passed value. -
fallback: The default value to use ifvalueisnil.
Returns: fallback if value is nil, else value is returned.
─────────────────────────
getTweenEaseByString(ease: string): stringFetches the tween ease based on the given string.
Parameters:
-
ease: The target ease.
Returns: The ease in FlxEase as a string, i.e. 'FlxEase.cubeOut'. Returns FlxEase.linear if the ease not found.
(Refer to FlxEase)
─────────────────────────
getTweenType(twnType: string|number): numberFetches the tween type based on the given value.
Parameters:
-
twnType: String of the tween's type or the abstract value (number).
Returns: The tween type in it's abstract value (number). Returns 8 (oneshot) by default if not found.
─────────────────────────
objectExists(obj: string): booleanChecks whether the given object exists in the variables map, as a lua object or in the current PlayState instance.
Parameters:
-
obj: The object to check.
Returns: true if the given object passes one of the checks.
─────────────────────────
variableExists(var: string): booleanChecks whether the given variable exists in the variables map.
Parameters:
-
var: The variable to check.
Returns: true if the variable exists.
─────────────────────────
luaObjectExists(obj: string): booleanChecks whether the given object exists as a lua object. This function is redundant on Psych Engine 1.0.0 and above as all "modchart" maps has been moved to the variables map instead. Consider using helper.variableExists instead.
Parameters:
-
obj: The object to check.
Returns: true if the object exists.
GhostUtil 3.0.0 • Docs 3.0.0, Revision 1
a Lua Library made by GhostglowDev; for Psych Engine
© 2025 GhostglowDev — Ghost's Utilities
Licensed under the MIT License.