Advertisement

Component System

Started by May 28, 2012 05:44 AM
9 comments, last by WitchLord 12 years, 6 months ago
I have a component based system in my engine. I want to be able to add additional components but through the used of Angelscript. Is that possible since angelscript does not allow you to extend C++ classes which are registered with the scripting engine. Any help would be greatly appreciated.
You could create a C++ component which wraps the scripted component inside. The C++ "shell" would forward messages/events, or anything else needed, to the scripted object. Also, you can register specially handled global properties to create the environment for the scripted component, ie. for example how it accesses its parent entity, or the scene.
Advertisement
It really depends on how you want the components to work.

It's true that AngelScript script classes cannot inherit from C++ classes, but that doesn't mean a script class cannot provide extended functionality. What can be done is only limited by how much effort you spend on the integration, i.e. the interface between the C++ application and the script application.

How do you want your components to work? If you can provide a few guidelines for what you're looking for I'm sure we can help you figure out how to implement it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I have figure out a way of doing it. I changed my component system to handle asIScriptObject as components. That way when i register an component wit ha game object i can get the pointer from angelscript and assign it to my game object.
I have a quick question. I got the id to an construct behaviour. I then execute the construct function through the scriptcontext. Everything went throught fine. Now how do i get the address of the object that was called through the asBEHAVE_CONSTRUCT. I try calling GetReturnObject from the context that execute the code but i keep getting null back.
Why are you calling the construct behavior directly? Why not just call asIScriptEngine::CreateScriptObject()?
Advertisement
Thanks Sicrane. Oh i did not know that this function exist.
asIObjectType* type = asEngine->GetObjectTypeByName("Vector2");
const char* name = type->GetName();
int typeids = type->GetTypeId();

I keep getting 67057 for the ID. then when i try to allocated memory for the object using the function sicrane metion it just crash.
Well it seems like no matter what function i call with type i just get access violation error.
Forget it. I solved it.

This topic is closed to new replies.

Advertisement