# Using C++ Classes within Scripts

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

## Recommended Posts

Hi guys, Realise this might be a bit of a stupid question, but although the C++ code for exposing a class to AngelScript is available all over the place, I can't seem to find an example of how to use such a class in the actual .as file. I have set all the factory functions and (I think) covered all the bases as regards exposing the class, but when I try to use it in AngelScript by simply using the class name, it gives an error. Below is the C++ code:
#include "f_baseentity.h"
#include "f_script.h"
#include "angelscript.h"

BaseEntity::BaseEntity()
{
refCount = 1;
}

BaseEntity* Ref_Factory()
{
return new BaseEntity();
}

{
refCount++;
}

void BaseEntity::Release()
{
if( --refCount == 0 )
delete this;
}

BaseEntity::~BaseEntity()
{
}

void BaseEntity::RegisterClass(FScript *script)
{
asIScriptEngine *engine = script->getEngine();
engine->RegisterObjectType("BaseEntity", 0, asOBJ_REF);
engine->RegisterObjectBehaviour("BaseEntity", asBEHAVE_FACTORY, "BaseEntity@ f()", asFUNCTION(Ref_Factory), asCALL_CDECL);
engine->RegisterObjectBehaviour("BaseEntity", asBEHAVE_RELEASE, "void f()", asMETHOD(BaseEntity, Release), asCALL_THISCALL);
}

I have tried a number of things in AngelScript, including inheritance, and also defining a class in AS with the same name and then inheriting from that, but no dice. Any help is much appreciated.

##### Share on other sites
Currently you can not inherit classes defined from c++. If you want to use the class you defined you can use it like
BaseEntity @entity = @BaseEntity();

##### Share on other sites
Here is a discussion on faking inheritance from C++ classes.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632930
• Total Posts
3009290
• ### Who's Online (See full list)

There are no registered users currently online

×