Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A JS-Like Scripting Language for a Game Written in Haxe?

I am developing a game in Haxe/Kha.

All I need is a scripting language that I can use for the game. It has to support things like variables and loops. I am making a JRPG where I have a lot of interact-ables (think loot chests, NPC's, etc.) so I want to script that instead of hard coding it in.

I hope to implement it in a JS-like language. I want to have 1 file per map, and for it to take this kind of format.

5, 10 {
    movement(WALK_RANDOM);
    function interact() {
        textBox("Hello World!");
        giveItem(RUBBER_DUCK);
    }
}

where the 5 and 10 are the x and y of the interact-able.

When I run this what I actually want to do is (in Haxe)

Interactable int = new Interactable(5,10);
int.movement = WALK_RANDOM;
int.interact = function () {textBox("Hello World!"); giveItem(RUBBER_DUCK);} // Can you even do this sort of thing in Haxe?

There would be one script file per map, and many of those interact-able clauses in that file.

TL;DR: I want to use a JS-style (perhaps actually JS?) scripting language to place stuff in my game. How should I put that into my game though, which is written in Haxe?

As you might have seen, I am genuinely lost and have no clue myself what I actually want to do. If there are any questions or parts I could elaborate on, please do point them out.

like image 747
M00nR4bb1t Avatar asked Jan 28 '23 10:01

M00nR4bb1t


1 Answers

Have you considered HScript?

https://github.com/HaxeFoundation/hscript

It's Haxe's official scripting solution. You can use Haxe itself (a subset of it rather) as an embedded scripting language. Functions and variables can be exposed to the script for it to interact with.

A more detailed description (though a bit Luxe-specific in some parts) can be found here:

http://snowkit.org/2015/06/20/using-hscript-to-program-entity-behaviors-in-luxe-with-auto-reload/

like image 172
larsiusprime Avatar answered Jan 31 '23 23:01

larsiusprime