Backwards Compatibility - AlsoGhostglowDev/Ghost-s-Utilities GitHub Wiki

backwards-compat.lua

Backwards Compatibility handler. Used to handle backwards compatibility between outdated versions of Psych Engine.

Be reminded that these versions only uses GhostUtil's counterpart of said function if it's not supported there; Else it'll fallback to the original Psych Engine function. If GhostUtil's version of a function were to bug out, please contact @ghostglowdev in Discord.

local bcompat = require 'ghostutil.backwards-compat'

Methods

startTween(tag: string, object: string, values: directory<string, dynamic>, ?duration: number, ?options: TweenOptions): void

Creates a tween of an object supporting multiple values for each respective fields.
(from Psych Engine 0.7.0)

Parameters:

  • tag: The tween's tag.
  • object: The target object to tween.
  • values: Directory containing values mapped to their corresponding field.
  • duration (optional): Determines how long the tween will take, defaults to 1.
  • options (optional): The tween's options; Refer to TweenOptions.

This function only uses GhostUtil's alternative way if the current Psych Engine version is under 0.7.0.

View Example

-- tweens boyfriend's x position to 100 alongside his velocity.x to 200.
-- the tween runs for 2 seconds with the expoInOut ease.
bcompat.startTween('tweenTag', 'boyfriend', { x = 100, ['velocity.x'] = 200 }, 2, {
    ease = 'expoInOut',
    onComplete = 'coolFn'    
})

-- gets called when the tween is completed.
function coolFn(tag, object)
    -- debug prints "tweenTag" (tag) and "boyfriend" (object).
    debugPrint(tag)
    debugPrint(object)
end

─────────────────────────

runHaxeFunction(funcToRun: string, ?args: table<dynamic>): dynamic

Calls a function from the current HScript / runHaxeCode instance.
(from Psych Engine 0.7.0)

Parameters:

  • funcToRun: The function to call.
  • args (optional): The arguments for the function, defaulted to an empty table.

Returns: The called function's return value if there's any.

This function only uses GhostUtil's alternative way if the current Psych Engine version is under 0.7.0.

View Example

runHaxeCode([[
    function coolFn(arg:String) {
        game.addTextToDebug(arg, 0xFF00FF00);
    }
]])

bcompat.runHaxeFunction('coolFn', {'oh look, its a green debug text!!'})

─────────────────────────

setHealthBarColors(left: string, right: string): void

Sets the health bar's colors.
(from Psych Engine 0.7.0)

Parameters:

  • left: The color to apply on the left side. Inputted as a string hexadecimal.
  • right: The color to apply on the right side. Inputted as a string hexadecimal.

This function only uses GhostUtil's alternative way if the current Psych Engine version is under 0.7.0.

View Example

-- just like the old times where the opponent will have a red colored healthbar,
-- meanwhile the player will have a green one.
bcompat.setHealthBarColors('FF0000', '00FF00')

─────────────────────────

setTimeBarColors(left: string, right: string): void

Sets the time bar's colors.
(from Psych Engine 0.7.0)

Parameters:

  • left: The color to apply on the left side. Inputted as a string hexadecimal.
  • right: The color to apply on the right side. Inputted as a string hexadecimal.

This function only uses GhostUtil's alternative way if the current Psych Engine version is under 0.7.0.

View Example

-- it's my color scheme!!
bcompat.setTimeBarColors('08FF9C', '10201A')

─────────────────────────

instanceArg(instanceName: string, ?classVar: string): string

Fetches the "instance string" of an instance to be used in reflection functions of which that accepts it.
(Shortcut to helper.instanceArg, from Psych Engine 0.7.2h)
(reflection functions that accepts instance strings are callMethod, callMethodFromClass, createInstance, setProperty, setPropertyFromGroup, setPropertyFromGroup and setVar)

Parameters:

  • instanceName: The instance's name.
  • classVar (optional): What class the instance is from, defaults to nil.
This function only uses GhostUtil's alternative way if the current Psych Engine version is under 1.0.0.

View Example

-- loads dad's graphic into my cool sprite
bcompat.callMethod('sprite.loadGraphicFromSprite', { bcompat.instanceArg('dad') })

─────────────────────────

callMethod(method: string, ?args: table<dynamic>): dynamic

Calls a method from PlayState's instance.
(Shortcut to helper.callMethod, from Psych Engine 0.7.0)

Parameters:

  • method: The method to call.
  • args (optional): The arguments to use for said method, defaults to an empty table.
    (You may need to use {''} instead for an empty table/argument in some versions.)

Returns: The called method's return value if there's any.

This function only uses GhostUtil's alternative way if the current Psych Engine version is under 1.0.0.

View Example

-- sets dad's position to (X: 200, Y: 300) 
bcompat.callMethod('dad.setPosition', {200, 300})

─────────────────────────

callMethodFromClass(className: string, method: string, ?args: table<dynamic>): dynamic

Calls a method from a class.
(Shortcut to helper.callMethodFromClass, from Psych Engine 0.7.0)

Parameters:

  • className: Class based on the source folder structure.
  • method: The method to call from said class.
  • args (optional): The arguments to use for said method, defaults to an empty table.
    (You may need to use {''} instead for an empty table/argument in some versions.)

Returns: The called method's return value if there's any.

This function only uses GhostUtil's alternative way if the current Psych Engine version is under 1.0.0.

View Example

-- loads up a youtube video on your default browser
bcompat.callMethodFromClass('backend.CoolUtil', 'browserLoad', {'https://www.youtube.com/watch?v=dQw4w9WgXcQ'})

─────────────────────────

createInstance(tag: string, className: string, ?args: table<dynamic>): dynamic

Creates an instance of the provided class with the specified arguments. The instance can later be used with other functions like setProperty.
(Shortcut to helper.createInstance, from Psych Engine 0.7.0)

Parameters:

  • tag: The tag to save the variable as.
  • className: Class based on the source folder structure.
  • args (optional): The arguments to use for the class' constructor, defaults to an empty table.
This function only uses GhostUtil's alternative way if the current Psych Engine version is under 1.0.0.

View Example

-- creates a new character instance with tag "pico"
bcompat.createInstance('pico', 'objects.Character', {100, 200, 'pico-player', true})

-- adds pico to the game
bcompat.addInstance('pico', true)

-- modifying the instance's properties
setProperty('pico.alpha', 0.2)

─────────────────────────

addInstance(tag: string, ?inFront: boolean): void

Adds the created instance to the game.
(Shortcut to helper.addInstance, from Psych Engine 0.7.0)

Parameters:

  • tag: The tag of the instance to add.
  • inFront (optional): If the instance should be infront of everything, defaults to false.
This function only uses GhostUtil's alternative way if the current Psych Engine version is under 0.7.0.

View Example

-- creates a new character instance with tag "pico"
bcompat.createInstance('pico', 'objects.Character', {100, 200, 'pico-player', true})

-- adds pico to the game
bcompat.addInstance('pico', true)

-- modifying the instance's properties
setProperty('pico.alpha', 0.2)

─────────────────────────

setProperty(variable: string, value: dynamic, ?allowMaps: boolean, ?allowInstances: boolean): void

Sets the property of the given variable in PlayState to value.
(Shortcut to helper.setProperty, instance support from Psych Engine 1.0)

Parameters:

  • variable: The variable to change.
  • value: The value to set the property to.
  • allowMaps (optional): Allows for map access in properties, disabled by default for optimization.
  • allowInstances (optional): Allows usage of instanceArg for properties, disabled by default for optimization.
This function only uses GhostUtil's alternative way if the current Psych Engine version is under 1.0.0.

View Example

-- applies a sprite's shader to boyfriend
bcompat.setProperty('boyfriend.shader', bcompat.instanceArg('sprite.shader'), false, true)

─────────────────────────

setPropertyFromGroup(group: string, index: number, variable: string, value: dynamic, ?allowMaps: boolean, ?allowInstances: boolean): void

Sets the property of the given group/array in PlayState to value.
(Shortcut to helper.setPropertyFromGroup, instance support from Psych Engine 1.0)

Parameters:

  • group: The variable's object group.
  • index: The index to the variable's object.
  • variable: The variable to change.
  • value: The value to set the property to.
  • allowMaps (optional): Allows for map access in properties, disabled by default for optimization.
  • allowInstances (optional): Allows usage of instanceArg for properties, disabled by default for optimization.
This function only uses GhostUtil's alternative way if the current Psych Engine version is under 1.0.0.

View Example

-- sets the first note's multAlpha to 0.5.
bcompat.setPropertyFromGroup('unspawnNotes', 0, 'multAlpha', 0.5)

─────────────────────────

setPropertyFromClass(className: string, variable: string, value: dynamic, ?allowMaps: boolean, ?allowInstances: boolean): void

Sets the property of the variable in the provided class to value.
(Shortcut to helper.setPropertyFromClass, instance support from Psych Engine 1.0)

Parameters:

  • className: The classpath of where the variable is from.
  • variable: The variable to change.
  • value: The value to set the property to.
  • allowMaps (optional): Allows for map access in properties, disabled by default for optimization.
  • allowInstances (optional): Allows usage of instanceArg for properties, disabled by default for optimization.
This function only uses GhostUtil's alternative way if the current Psych Engine version is under 1.0.0.
View Example

-- sets isPixelStage to true.

--[[
  Q: Why can't this be done in setProperty instead?
  A: isPixelStage is a static variable, only exists within the class itself.
]]
bcompat.setPropertyFromClass('states.PlayState', 'isPixelStage', true)


GhostUtil 3.0.0Docs 3.0.0, Revision 1

a Lua Library made by GhostglowDev; for Psych Engine
© 2025 GhostglowDevGhost's Utilities
Licensed under the MIT License.

⚠️ **GitHub.com Fallback** ⚠️