JS Integration (newbie question)

Hi there,

I am new to game dev, but a web dev senior and I seek a game engine to fit our web stack.

Please, when HTML5 is a target, it is possible to:
a) call outside JS methods (or send messages) from inside Defold (lua) ?
b) call inside Lua methods (or send messages) from outside JS web context ?

Can you provide an example?

Thanks! Defold looks very promising, nice, clean and fast.

Happy holidays

F

a) Yes, easy. Just use html5.run().
b) Not that I know of (but I may be wrong). You will need to check for JS messages from the Lua side.

1 Like

Hi there,

thanks for a reply … by a b) you mean to check periodicaly some JS variable set from outside world with html5.run method ? Imagine, that game controls come from this outside-world variable. Where should be this code put inside Defold project?

Thanks, F

Yes, exactly.

Hmm. Well, you are free to put it wherever you want. html5.run() can be called from anywhere. I think the “best practice” will depend on how your project is structured. If you have a simple game with only a single “player” script, you could put the code there. For me, I would keep it a bit more modular. Have an “input manager” script in the root collection of your project that manages the JS <—> Lua communication, and either send messages directly from that script, or have a Lua module in-between that handles subscription.

1 Like

Hi Ross,

thanks … so what I want can be accomplished … thats great. I will dive more into Defold then :slight_smile:

Merry Christmas & thanks!

F

3 Likes