Skip to main content

PythonScript

Kindclass
Packagepsychlua
Full namepsychlua.PythonScript
Sourcesource/psychlua/PythonScript.hx
Compiled when#if PYTHON_ALLOWED

A Python script running inside the engine, powered by the pure-Haxe Hython interpreter (haxelib hython). Mirrors FunkinLua's API so Python mods behave exactly like Lua mods: define top-level def callbacks (onCreate, onUpdate, goodNoteHit, ...), call the same engine functions and return the same sentinels (Function_Stop, Function_Continue, Function_StopAll).

Public fields​

NameTypeStaticDefaultNotes
Function_StopDynamicyes"##PSYCHLUA_FUNCTIONSTOP"#if PYTHON_ALLOWED · Sentinel strings are intentionally the SAME values as FunkinLua's so the existing ret != FunkinLua.Function_Stop checks keep working for Python.
Function_ContinueDynamicyes"##PSYCHLUA_FUNCTIONCONTINUE"#if PYTHON_ALLOWED
Function_StopAllDynamicyes"##PSYCHLUA_FUNCTIONSTOPLUA"#if PYTHON_ALLOWED
Function_StopLuaDynamicyes"##PSYCHLUA_FUNCTIONSTOPLUA"#if PYTHON_ALLOWED · Lua-compatible alias (#51): the documentation and the shared hook table tell Python authors to return Function_StopLua; it carries the same sentinel, so PlayState's Function_StopAll comparison matches it.
scriptNameStringno''#if PYTHON_ALLOWED
modFolderStringnonull#if PYTHON_ALLOWED
closedBoolnofalse#if PYTHON_ALLOWED
lastCalledFunctionStringno''#if PYTHON_ALLOWED
lastCalledScriptPythonScriptyesnull#if PYTHON_ALLOWED
sandboxedBoolnofalse#if PYTHON_ALLOWED · Runtime half of the softmod sandbox; set before Hython is created.
securityModNameStringnonull#if PYTHON_ALLOWED
securityAllowlistArray<String>no[]#if PYTHON_ALLOWED
customFunctionsMap<String, Dynamic>yes[]#if PYTHON_ALLOWED
registeredFunctionsMap<String, Dynamic>yes[]#if PYTHON_ALLOWED

Public methods​

new (constructor)​

function new(scriptName:String, ?scriptCode:String)

Only compiled when #if PYTHON_ALLOWED.

ParameterTypeDefault
scriptNameString—
scriptCode (optional)String—

View source

call​

function call(func:String, args:Array<Dynamic>):Dynamic

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

ParameterTypeDefault
funcString—
argsArray<Dynamic>—

View source

set​

function set(variable:String, data:Dynamic)

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

ParameterTypeDefault
variableString—
dataDynamic—

View source

reportSecurityRuntime​

function reportSecurityRuntime(capability:String, line:Int = 0):String

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

Log a runtime guard failure to both the mod console and process log.

ParameterTypeDefault
capabilityString—
line (optional)Int0

View source

allowsSecurityRule​

inline function allowsSecurityRule(rule:String):Bool

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

ParameterTypeDefault
ruleString—

View source

allowClassAccess​

function allowClassAccess(className:String):Bool

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

ParameterTypeDefault
classNameString—

View source

get​

function get(variable:String):Dynamic

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

ParameterTypeDefault
variableString—

View source

stop​

function stop()

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

View source

pyTrace​

function pyTrace(text:String, ignoreCheck:Bool = false, deprecated:Bool = false, color:FlxColor = FlxColor.WHITE)

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

ParameterTypeDefault
textString—
ignoreCheck (optional)Boolfalse
deprecated (optional)Boolfalse
color (optional)FlxColorFlxColor.WHITE

View source

getVar​

function getVar(variable:String):Dynamic

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

ParameterTypeDefault
variableString—

View source

registerFunction​

static function registerFunction(name:String, func:Dynamic):Void

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

ParameterTypeDefault
nameString—
funcDynamic—

View source

isOfTypes​

static function isOfTypes(value:Any, types:Array<Dynamic>)

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

ParameterTypeDefault
valueAny—
typesArray<Dynamic>—

View source

getInstanceStatic​

static inline function getInstanceStatic()

Only compiled when #if PYTHON_ALLOWED + #if ACHIEVEMENTS_ALLOWED Achievements.addPythonCallbacks(this); #end + #if DISCORD_ALLOWED DiscordClient.addPythonCallbacks(this); #end + #if flxanimate FlxAnimateFunctions.implementPython(this); #end.

View source

Internals​

Private / internal members
FieldTypeStatic
interpInterpno
parserParserno
_missingCallsMap<String, Bool>no
Method
static function preprocessHythonCode(code:String):String
static function getErrorString(e:Error):String
function registerCustomFunctions()
function addLocalCallback(name:String, myFunction:Dynamic)
function getInstance():Dynamic
inline function getTextObject(name:String):FlxText
function getGroupStuff(leArray:Dynamic, variable:String)
function setGroupStuff(leArray:Dynamic, variable:String, value:Dynamic)
function loadFrames(spr:FlxSprite, image:String, spriteType:String)
function resetTextTag(tag:String)
function resetSpriteTag(tag:String)
function cancelTween(tag:String)
function tweenPrepare(tag:String, vars:String)
function cancelTimer(tag:String)
static function addAnimByIndices(obj:String, name:String, prefix:String, indices:String, framerate:Int = 24, loop:Bool = false)