Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Script API 0: What is a Script?

lunarcleint edited this page Nov 6, 2022 · 4 revisions

What is a Script?

A script is a file with hscript code inside it, it must have one of these file extensions ["hx", "hscript", "hsc", "hxs"].

It is important to know that these Haxe syntaxes are not supported in hscript:

Default packages and Functions

Script Functions (Added By Default)

  • var name:String This will either be the file name, or "stage" if its a stage.
  • function new() Called when script is created.
  • function destroy() Called when script is destroyed.
  • function update(elapsed:Float) A function that is called every frame.
  • function trace(_) This function will trace any objects you put in it, trace("hi", "t") //prints hi,t
  • function import(path:String, ?as:Null<String>) Will import as the haxe function would work, this only imports classes. It is important to treat the haxe classes you import carefully since they maybe be turned into another type depending on the platform.
  • function addScript(scriptName:String):Dynamic This will add any script in scripts/, this functions also returns getScript(scriptName)
  • function getScript(scriptName:String):Dynamic This will give the script's local functions and variables as a Dynamic object.
  • ScriptReturn a shortcut to the enum ScriptReturn

See more on Preset Variables: Script API 1: All Preset Variables

Running a Script

There are 4 types of scripts you can run:

  • Song Scripts: These are any scripts in the folder of the current song you are playing (it will run all of them even if inside another folder)
  • Stage Scripts: These are scripts in the /stages folder with the exact same name as the stage's json, will have the script name "stage"
  • Character Scripts: These scripts run whenever any character is created in PlayState, same file name as json
  • Global Scripts: These are any scripts inside the folder scripts/global and any folders in there too

Clone this wiki locally