Scripting

Started by
5 comments, last by Hodgman 7 years, 10 months ago

Hello. I've been implementing a 2D game engine, mostly for learning purposes. I got a basic ECS working and I was wondering how can I implement a scripting component, something like Unity does, that would allow the end-user to easily manipulate entities and their behaviours.

Advertisement

Start of by picking a scripting language to use, Python, Lua and Angelscript are common choices.

For lua check out this blog as a start: https://eliasdaler.wordpress.com/2013/10/11/lua_cpp_binder/
Angelscript has a forum here on Gamedev.net http://www.gamedev.net/forum/49-angelcode/

@spinningcubes | Blog: Spinningcubes.com | Gamedev notes: GameDev Pensieve | Spinningcubes on Youtube

To be more specific, I'm not looking for a binding or a scripting language. I'm looking for a way to make it easy for the end-user to create and manipulate entities. Thank you for those links, the lua one is really useful!

...mostly for learning purposes

...I'm looking for a way to make it easy for the end-user to create and manipulate entities.


The second one can be quite complicated. In light of the first, it might be a better idea for you to start learning the basics of integrating a scripting language, as well as all the other things you need to learn. With experience, you might gain some useful insight into the latter one.

The actual integration of a scripting language can be complex. The highest level is a straight-across, 1 for 1 binding of your API. Somebody (I think it was Hodgman) once linked a colorful article about why that might not be the best idea, but I didn't save the link. The gist of it, though, is that languages like Lua are different beasts than C++, and if all you're going to do is a 1 for 1 API binding, you're probably better off just using C++.

To go beyond 1 for 1 binding, though, takes a little bit of engine-specific ingenuity. One engine, I use, Urho3D, implements Lua and AngelScript binding using the 1 for 1 API exposure, but they also integrate a ScriptObject component that can be added to an object. This component acts as a glue layer, passing events across the Lua/C++ or AS/C++ boundary.

Still, I suggest you spend some time playing with things, rather than trying to design something easy to use by end-users right out of the gate.

I thought that trying to implement this would be a nice challenge and an interesting feature. Thank you for your reply and I will most definitely not jump straight into it but I'm still looking for an idea.

If all you want is your users to be able to change some parameters and don't need a whole programming language, you may consider instead using a plain text data description file format, such as ini, yaml or json. There are lots of parsers available in many languages.

Definition of a man-year: 730 people trying to finish the project before lunch

Scripting is just another word for programming, and "scripting languages" are still just programming languages. So the question is really: In my ECS framework, how can I make a component that the user programs :)

Figuring out the what and why of this question in much more detail will be very useful, before you dive into a 2nd programming language as the how.

This topic is closed to new replies.

Advertisement