-
Notifications
You must be signed in to change notification settings - Fork 7
Lua Script API: HScript Functions
runHaxeCode(code:String, ?vars:Array<Any> = null, ?func:String = null, ?args:Array<Dynamic> = null):Void
Runs a Haxe code and interpretes the code within a Lua script.
-
code
- The given code to be interpreted. -
vars
- An optional parameter, the given variables to import within code; must be a table dictionary. -
func
- An optional parameter, the said given function within the code to call itself. -
args
- An optional parameter, the certain amount of arguments to passed within the function, if said arguments exists.
Examples:
A simple Haxe code, creates a custom text by utilizing the
Alphabet
class from theobjects
library package.
runHaxeCode([[
import objects.Alphabet;
var awesome = new Alphabet(0, 0, 'Awesome', true);
awesome.cameras = [game.camHUD];
add(awesome);
]])
Imports variables that randomizes integer numbers to be used to calculate the area of an ellipse.
runHaxeCode([[
function areaEllipse(aAxis:Float, bAxis:Float):Float {
return Math.PI * aAxis * bAxis;
}
debugPrint(areaEllipse(awesomeNumber1, awesomeNumber2));
]], {awesomeNumber1 = getRandomInt(0, 10), awesomeNumber2 = getRandomInt(0, 10)})
Calls the area of an ellipse function and prints its calculated area. This is probably used to overcome some obscure bug from the
runHaxeCode()
function, when printing within functions.
runHaxeCode([[
function areaEllipse(aAxis:Float, bAxis:Float):Float {
debugPrint(Math.PI * aAxis * bAxis);
}
]], nil, 'areaEllipse', {54, 43})
Runs a function from the previous interpreted Haxe code within a Lua script.
-
func
- An optional parameter, the said given function within the code to call outside the code from. -
args
- An optional parameter, the certain amount of arguments to passed within the function, if said arguments exists.
Example:
Calls a bunch of formulas outside the Haxe code.
runHaxeCode([[
function areaPyramid(baseLength:Float, baseWidth:Float, height:Float):Float {
var calcDimensions = (baseMain:Float, baseAlt:Float) -> {
return baseAlt * Math.sqrt( Math.pow((baseMain/2), 2) + Math.pow(height, 2) );
}
var dimensionLength = calcDimensions(baseLength, baseWidth);
var dimensionWidth = calcDimensions(baseWidth, baseLength);
return (baseLength * baseWidth) + dimensionLength + dimensionWidth;
}
function areaCone(radius:Float, height:Float):Float {
return Math.PI * radius * (radius + Math.sqrt( Math.pow(height, 2) + Math.pow(radius, 2) ));
}
]])
debugPrint( runHaxeFunction('areaPyramid', {3, 4, 5}) ) --> 49.036107439225
debugPrint( runHaxeFunction('areaCone', {12, 33}) ) --> 1776.1597151886
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