Topic: Some questions regarding the scripting system

Hi all,

I'm coming from Polycode, which is a similar engine in many ways, but at a much earlier development stage.

I have a few questions regarding the scripting system which I could not answer through searching the forums.

First of all, if multiple scripts have to be included by using the `dofile()` function in the main scripting file, is it possible to include them by using the `require` function instead? Is there anything specific in Maratis' implementation that prevents that?

Secondly, is there any entity-component system in place currently? Specifically, similar to Unity's. I am guessing that the answer is "no", since no properties can be added to an entity in the editor. I plan on implementing a plugin that remedies that, but it would be nice to know if the work would duplicate someone else's effort (in which case I can just help with that).

Third, is the Lua API generated or hand-written? There are number of tools that generate 1 to 1 C++ to Lua APIs, but I am not sure if this is the case here.

Lastly, are there any guidelines regarding contributing to the source code?

Thanks in advance!

Last edited by kirilz (2013-07-25 21:25:53)

Re: Some questions regarding the scripting system

Hi,
welcome : )

- About require, nothing is preventing using it, but there is some limitation for now :
the dofile call has been modified to simplify the path search and to be able to access files inside a package transparently (npk packing), the same thing is not done yet for require.

- There is a behavior system to create complex entities behaviors, it can be extended in c++ using a game plugin, you can find some examples in maratis website and in the wiki (like "WaterDemo" implementing fish behaviors : http://www.maratis3d.org/?page_id=53).

The basics are explained here : http://www.maratis3d.org/?p=500

- the lua API is hand-written.

For contribution to the official dev we can talk by mail about the planned evolution and some themes you could be interested of. Big help is needed to make small games/examples to test the pipeline and show how Maratis can be used, there is some key features to develop or improve like the lua API, Android port, publishing pipeline, particles system, level of detail, basic behaviors etc

General roadmap in the wiki : http://wiki.maratis3d.org/index.php?title=Roadmap

Re: Some questions regarding the scripting system

Hi Kirilz,

Welcome to Maratis!

I was looking into trying to implement require recently but I never got around to it. I think there are some assumptions about what it does, regarding setting up modules and so on, which I haven't quite figured out yet.

About the behaviour system, I've recently been working on a couple of plugins one of which provides scriptable behaviours like you suggested. It's still pretty early on but it more or less works. The multiple plugin framework is currently only available through a build of the community branch of the engine, but I'm hoping to find the time soon to go through and test it fully so I feel confident enough to push it to the official repository.

Most of the stock lua API is very c-like, not reflecting objects at all. This, I believe, is done to keep the API simple. I have also been trying to make an optional object oriented API on top of this with the plugins, but using an automatic reflection thing I think might complicate the simple API a bit, plus, the system as-is, is pretty detached from the scripting system, adding automatic reflection would more heavily couple it to pretty much all the classes in the engine.

Re: Some questions regarding the scripting system

Thanks for the replies all.

Something I forgot to ask, what is the status of the networking features in the engine?

Nistur, what I am thinking about doing is implementing a module that allows you to use components(that hold data only) and behaviors(that operate on that data) as building blocks with which to compose your game entities. I did see your plugins and am reading through them to get more familiar with how Maratis is working.

Re: Some questions regarding the scripting system

There's no networking support in Maratis yet, it's another of the things I've looked into, but I've not yet found a nice library to base any work off, and I've not had the time or energy to write the system from scratch. In theory writing a bespoke networking library for a specific task is relatively easy, writing a generic one to suit an engine is considerably more difficult, so it might be that you're better off rolling your own and/or enlisting someone to help with your specific case. If you're feeling kind, the work could be rolled back into Maratis and made more generic for the community to use tongue

I would be interested to know precisely what the plan is for the component/behavior system you have in mind. I think it should be possible to leverage MScriptableBehavior to do what I think you're wanting

Re: Some questions regarding the scripting system

HI nistur etal re: networking


I thought you liked grapple a bit, at least enough to base something off of ?

It looked like a solid offering for game networking to me, though I"ve never really dug into it.

Re: Some questions regarding the scripting system

Data driven component systems aren't anything new, that's how Unity and the latest Unreal work. Pretty much this https://en.wikipedia.org/wiki/Entity_component_system. There was also a good description of this pattern in the book "Game Engine Architecture", which is a quite excellent read.

That said, while a quick-and-dirty implementation can be done in a day(hardcoding the component classes in C++), I am a bit of an idealist and would like to aim for maximum flexibility. Ideally I would like to write the data definition of a game entity in Lua, add triggers that apply certain behaviors (also defined in Lua), but store and operate on the data in C++.

P.S. E.g. Unity: http://docs.unity3d.com/Documentation/M … nts40.html Note that some components simply have to be hardcoded, such as the physics, graphics, audio, etc. The rest, such as stats, abilities, dialog lines, can be defined purely in script.

Last edited by kirilz (2013-07-27 04:08:13)

Re: Some questions regarding the scripting system

I'm familiar with how Unity's Entity/component system works (also, I think I have that book somewhere). I think I was just a little confused by you splitting the data (component) from the functionality (behaviour).

The Maratis behaviour system currently uses an XML format for all the data. There is no way (yet) to reflect this properly in the script using MScriptableBehaviour but it's something I am working on. It is possible to use the standard lua API to access behaviours in C++ behaviours currently (GetBehaviorVariable, SetBehaviorVariable)

I'm still not entirely sure what your "ideal" design is for this, but my current plan is:
- define 'types' in lua such as MVariableString which are tables with :get and :set functions and, if invoked with parameters, set a default value ( MScriptableBehaviour "player" { speed = MVariableInt(3), } )
- from the C++, the class can query the definition with things such as script->callFunction("player.getVariablesNumber") and then initialise an internal list of the data (which can then be removed from the lua side completely) for exposure through MScriptableBehaviour::getVariable
- the lua "MVariable" table can then be used with :get and :set functions which will automagically call through to the standard getBehaviorVariable/setBehaviorVariable function (no data stored in lua, no chance of going out of sync)

I haven't even begun to implement this, so I have no idea if there are any hidden gotchas yet. But it looks (to me) to be a workable solution. Any thoughts?

heartseed wrote:

I thought you liked grapple a bit, at least enough to base something off of ?

I did quite like grapple, but it hasn't been maintained for 4 years (not a problem if it mostly works but looks like there are no grapple experts to quiz if things go wrong) and I could never get Windows support working, although, to be fair, I didn't try _overly_ hard. It's an option, but it's not really ideal.

Re: Some questions regarding the scripting system

There is a way in lua to control objects : http://wiki.maratis3d.org/index.php?tit … ng_example
it can be helpful for some entities, however everything need to be written in lua and cannot be manipulated by the editor compared to the behavior system.

It is seductive to think about a data editor inside maratis to manipulate game variables, I taught about it when writing the behavior system, but I realized that it will be hard to be flexible enough and anticipate what a game will need (float, string are easy, but maybe you will need to store a complex table, a matrix or else).

kirilz, you wrote you'd like to write the data definition in lua but operate it in c++, if you operate the data in c++ it means you have to know the structure of the data in your c++ code, so why no define the data in c++ ?

What I'd like to discuss, and it's what I try to ask Nistur too, is a practical situation in a game that can be studied, like :
- a game with one player and 2 types of enemy :
  - player : can move around a level. It's variable are : speed, life, score, field of view
  - enemy 1 : is attracted by player, touching the player reduce player life depeinding on it's power. It's variable are : speed, power
  - enemy 2 : is attracted by player when out of player field of view, and repulsed by enemy 1 if it's power is inferior as the one of enemy 1. It's variable are : speed, power

we should :
- be able to change the variables in-editor to fine-tune the game
- the entities interactions should be updated automatically
- I'd like to call special actions triggered in lua
etc

Re: Some questions regarding the scripting system

I think the issue with lua is how dynamic the language is. If we remove it and make the MVariables static types then that reduces the issues significantly. Exposing lua variables in the editor will be possible.

With regards to the example you gave. If the movement is straight line, I could have that working for you before the end of the weekend if you really wanted using MScriptableBehaviour. If you want proper path finding, you'll have to wait for MRecast to be hooked up.

anael wrote:

- be able to change the variables in-editor to fine-tune the game

I really don't see the editor variables being a huge issue (although I am expecting a few perculiarities when trying to access the base class stuff from the editor)

anael wrote:

- the entities interactions should be updated automatically

I'm not entirely sure what you mean by this. MScriptableBehaviour currently gives you onBegin update and onEnd callbacks. If you would want collision callbacks then it _should_ be fairly easy*

anael wrote:

- I'd like to call special actions triggered in lua

Again, not entirely sure what you mean by that. MScriptableBehaviour is entirely in lua. It uses the same lua state as the scene script, so you have the same environment. If you want to call actions yourself, it is possible.

If you have a specific use case, like the one above, I'd be very happy to know because it can help me make the system more well rounded and gives me test cases to make sure it works smile

* There is currently nothing like this in MScriptableBehaviour, but I can make a MEntity table in lua that will handle things like physics callbacks and behaviour lists. It can then call onCollision on any behaviours that implement that function...

Last edited by Nistur (2013-07-27 15:57:18)

Re: Some questions regarding the scripting system

Nistur, this was just a random example, as everything in it can be done already.

I'm just saying that a good starting point to plan gameplay tools, is a real game situation and it's need
(one looking like this random example).
To point out was is possible and what is not possible with the current version of Maratis.

Re: Some questions regarding the scripting system

For example, if I continue on this random example, the way I would do it is like this :

- create a game plugin in c++ with 3 behaviors (player, enemy1, enemy2)
- a custom MGame class if necessary (for example to handle path finding or global events)
- the variables (speed, power) will be attached to each behavior so it will be possible to edit their value in-editor
- a custom draw function for the player behavior to draw the field-of-view in-editor as an helper
- custom script functions in c++ to call special actions from lua
- the scene specific logic in lua

Re: Some questions regarding the scripting system

I'm sorry I misunderstood then. Yes, it's all possible. I've been working into moving game specific stuff (like the behaviours) into lua to allow easier/quicker development.