Behavior Scripting Questions

Hey everyone!

First off, long live Chaiscript! I love this language and am having such a blast learning to include it in my current project (a simple 2D RPG-like game). Just one question.

Hopefully I can explain this well enough, but I wanted to see if this is really a good way to manage this problem. In my engine I have scene objects (called GameNodes). Each of them can have a script attached to them. Each Script may (or may not) have methods like “OnLoad()” or “OnUpdate()”. If possible I’d love to define classes in the script, then have the engine create instances of those objects and update them when appropriate. Any advice?

Here would be an example of the sort of Chaiscript I’d like to use.

class TestBehavior
{
    var test;

    def TestBehavior()
    {
        test = "Hello World!";
    }

    def OnLoad()
    {
        test = "Now I'm changed!";
    }

    def OnUpdate()
    {
        print(test);
    }

    def OnDestroy()
    {
        print("Bye bye!");
    }
};

So my questions I guess is, can I blindly create an instance of this class in C++ (since the program won’t know all the classes at compile time). Or do I need to reassess how I’m doing this?

If I can create instances in C++, my plan is to store std::function(s) in a Script object for my engine to reference and call.

Sorry for the long post, hopefully this makes some amount of sense :stuck_out_tongue:

Thanks in advance!

Daniel Jackson