-
Notifications
You must be signed in to change notification settings - Fork 7
Lua Script API: HScript Functions
Imports haxe libraries into the interpreter. Basically an import
statement in Haxe which imports specific packages into Haxe like sprites, text, tweens, etc.
-
libName
- The library name to be referenced. -
libPackage
- An optional parameter, The library package to use.
Examples:
- Imports the sound library:
addHaxeLibrary('FlxSound', 'flixel.system')
- Imports shader filters:
addHaxeLibrary('ShaderFilter', 'openfl.filters')
- Imports CoolUtil:
addHaxeLibrary('CoolUtil')
Import Haxe (Reference):
package; // they are directories that contain modules, i dunno how it works; but very important to use.
// import library_package.library_name | <-- That's the syntax
import flixel.system.FlxSound; // Imports the sound package
import openfl.filters.ShaderFilter; // Imports the shader filter package
import CoolUtil; // Imports CoolUtil haxe file, i think
// Also the semi colon ';' character is very important when declaring functions, packages, variables, etc.
Pre-imported Libraries:
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxCamera;
import flixel.util.FlxTimer;
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;
import flixel.util.FlxColor;
import states.PlayState;
import backend.Paths;
import backend.Conductor;
import backend.ClientPrefs;
import objects.Character;
import objects.Alphabet;
import objects.Note;
import psychlua.CustomSubstate;
import backend.BaseStage.Countdown;
import flixel.addons.display.FlxRuntimeShader;
import openfl.filters.ShaderFilter;
import StringTools;
runHaxeCode(codeToRun:String, ?varsToBring:Any = null, ?funcToRun:String = null, ?funcArgs:Array<Dynamic> = null)
Runs your haxe code for your Hscripts and stuff.
-
codeToRun
- The haxe code to be run, use double brackets[[]]
for multiline strings. -
varsToBring
- An optional parameter, The Haxe variable(s) to import for string interpolation; Must be a table dictionary. -
funcToRun
- An optional parameter, The Haxe function name to be referenced. -
funcArgs
- An optional parameter, The argument(s) to be passed to the Haxe function.
Example:
function onCreate()
runHaxeCode([[
debugPrint(text, color); // will print > 'hi'
]], {text = 'hi', color = 0xFF0000})
end
Executes the Haxe function from the runHaxeCode()
function.
-
funcToRun
- The Haxe function name to be referenced. -
funcArgs
- An optional parameter, The argument(s) to be passed to the Haxe function.
Example:
function onCreate()
runHaxeCode([[
function isBool(bool:String) { return bool == 'true' ? true : false; }
]])
local proof = runHaxeFunction('isBool', {'true'})
debugPrint(type(proof)) -- will print > 'boolean'
end
Works exactly the same as setVar()
function in Lua.
-
varName
- The variable to be referenced. -
value
- The specified type of value for the variable to use or to over-write.
Example:
function onCreate()
runHaxeCode([[
setVar('globalVar', 'Hello Haxe!');
setVar('globalYes', [34, 123, 4.20]);
]])
runHaxeCode([[
debugPrint(getVar('globalVar'), 0xf88700); // will print > 'Hello Haxe!'
debugPrint(getVar('globalYes')[2], 0xf88700); // will print > 4.20
]])
-- Calling a Global Haxe Variable into Lua
debugPrint(getProperty('globalYes')[1]) -- will print > 34
debugPrint(getProperty('globalYes')[2]) -- will print > 123
end
Works exactly the same as getVar()
function in Lua.
-
varName
- The variable to be referenced.
Removes the global variable permanently, if not used anymore.
-
varName
- The variable to be referenced.
Works exactly the same as the debugPrint()
function.
-
text
- The text to be outputed to the top-left of the screen. -
color
- An optional parameter, The color for the text to be displayed.
Gets the specified tag object outside the runHaxeCode()
function.
-
tag
- The object tag name to be referenced.
Example:
function onCreate()
makeLuaSprite('graphicThingy', nil, 0, 0)
makeGraphic('graphicThingy', 1000, 1000, 'ff00ff')
addLuaSprite('graphicThingy', true)
runHaxeCode([[
var theLuaTag = game.getLuaObject('graphicThingy'); // gets the lua tag
theLuaTag.cameras = [game.camHUD]; // Sets it into 'camHUD'
theLuaTag.alpha = 0.5; // Sets the opacity to '0.5'
theLuaTag.angle = 180; // Sets the angle to '180'
]])
end
Note from LarryFrosty: The only way I could get this function working was if I used it in a lua script along with runHaxeCode. Third argument returns null every single time. If there's any info about this function, I'd love to hear it.
Creates a local function inside the script.
-
name
- The given name of the callback function. -
func
- The function code to use. -
funk
- Not known, refer to the note.
Example:
function onCreate()
runHaxeCode([[
createCallback('print', function(text:String) {
debugPrint(text);
});
]])
end
function onCreatePost()
print('Hello') -- will print "Hello"
end
Creates a global function across all lua scripts.
-
name
- The given name of the global callback function. -
func
- The function code to use.
Example:
Script 1 (Haxe):
function onCreate() {
createGlobalCallback('print', function(text:String) {
debugPrint(text);
});
}
Script 2 (Lua):
function onCreatePost()
print('Hello') -- will print "Hello"
end
Is the page in some way inaccurate? an error, a typo, or outdated data? To report it, use the "Issue Tab". Or do you wish to include a new function or add new information? use the "Pull Request Tab". Help is always appreciated!
- Event Callbacks
- Custom Sprite
- Custom Text
- Object Functions
- General Functions
- Scripting & File Functions
- Game Input Control Functions
- Language Translation
- HScript Functions
- Custom Substates
- Custom Shaders
- Deprecated & Removed Functions
- Sound & Music Functions
- Tweens & Timers Functions
- Reflection Functions
- Variables