• Advertisement
Sign in to follow this  

Component System

This topic is 2093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. Edited by BornToCode

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. Edited by BornToCode

Share this post


Link to post
Share on other sites
Why are you calling the construct behavior directly? Why not just call asIScriptEngine::CreateScriptObject()?

Share this post


Link to post
Share on other sites
Thanks Sicrane. Oh i did not know that this function exist. Edited by BornToCode

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Well it seems like no matter what function i call with type i just get access violation error.

Share this post


Link to post
Share on other sites

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.


To create an object you would need to call the factory, not the constructor. The factory is responsible for allocating, initializing (via the call to the constructor), and then return the handle to the newly created object.

The factory functions are found with the asIObjectType::GetFactoryByDecl() method.

CreateScriptObject() works by calling the default factory, i.e. the one that doesn't take any arguments. If you want to use any of the factories that takes arguments you'll have to manually call it by setting up a context and then use that to execute the factory.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement