• Create Account

Banner advertising on our site currently available from just \$5!

### #Actualslicer4ever

Posted 14 June 2013 - 12:58 PM

The memory for the script class is not meant to be allocated manually by the application. The script engine must allocate and initialize the memory. A script class doesn't just contain the members declared by the script, there are also hidden data (object type, ref counter, etc) that the application shouldn't manipulate directly.

May I ask why you want to do something like this? Perhaps there is another way.

thanks for the response Andreas=-)
this is basically what i'm attempting to achieve. my game has a generic "Ability" class, what i'd like to do is use angelscript to manage what an ability does, this means different scripts, have different needs. in the past, i wrote a generic container(essentially a dictionary add-on), that got attached to each instance of the class, and the script could customize that container as it needed. the problem with this approach was doing the look-ups into the container to get the appropriate information the script needs.

I was hoping that their would be a way to directly map memory that the script needs to some class, so that i could store a pointer to the scripts unique class in the c++ ability object.

basically, i want to create an instance of a class(this class is unique to each script), attach it to the ability object, and then when the ability is passed to a generic "update" function in the script, it can pull the custom class pointer from the ability object, and i don't have to do any ugly look-ups to continue working/evaluating what an ability is doing.

i think it'd look like this in angelscript:

class Data{
int y;
};

void Initialize(Ablity @Ab){
Data @x = Data();
Ab.SetDataObject(x);
};

void Update(Ability @Ab){
Data @x = @Ab.GetDataObject();
x.y = 100;
};

obviously not exact, but it's what i'd like to achieve. (essentially script creates class, hands it to the engine to store, and then pulls it out as it needs it. but the engine has zero idea what the class looks like.) I'm fairly certain the generic handler can achieve this, i just don't know how to register my engine to support this setup.

edit:

I've been working on this a bit more, and think i almost have it. I switched my c++ script to hold a pointer to the CScriptHandle object, like so:


class Obj{
private:
CScriptHandle *m_Handle;
public
void SetScriptHandle(CScriptHandle *Handle){
m_Handle = Handle;
}

CScriptHandle *GetScriptHandle(void){
return m_Handle;
}
};

//Registered like so:
ScriptEngine->RegisterObjectMethod("Obj", "void SetScriptHandle(ref &in)", asMETHOD(Obj, SetScriptHandle), asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Obj", "ref &GetScriptHandle()", asMETHOD(Obj, GetScriptHandle), asCALL_THISCALL);


I then use it like so:

class Data{
int x;
};

void Func(Obj @A){
Data @x = Data();
x.x = 0;
A.SetScriptHandle(x);
A.GetScriptHandle();
};

the above code sets the script handle into the function correctly, and has an appropiate ref object inside the CScriptHandle class. but when i call GetScriptHandle, the CScriptHandle class suddenly no longer has it's ref object. i'm assuming angelscript is releasing x from the ref object, but i have no idea how to keep it in the engine.

### #2slicer4ever

Posted 13 June 2013 - 11:18 PM

The memory for the script class is not meant to be allocated manually by the application. The script engine must allocate and initialize the memory. A script class doesn't just contain the members declared by the script, there are also hidden data (object type, ref counter, etc) that the application shouldn't manipulate directly.

May I ask why you want to do something like this? Perhaps there is another way.

thanks for the response Andreas=-)
this is basically what i'm attempting to achieve. my game has a generic "Ability" class, what i'd like to do is use angelscript to manage what an ability does, this means different scripts, have different needs. in the past, i wrote a generic container(essentially a dictionary add-on), that got attached to each instance of the class, and the script could customize that container as it needed. the problem with this approach was doing the look-ups into the container to get the appropriate information the script needs.

I was hoping that their would be a way to directly map memory that the script needs to some class, so that i could store a pointer to the scripts unique class in the c++ ability object.

basically, i want to create an instance of a class(this class is unique to each script), attach it to the ability object, and then when the ability is passed to a generic "update" function in the script, it can pull the custom class pointer from the ability object, and i don't have to do any ugly look-ups to continue working/evaluating what an ability is doing.

i think it'd look like this in angelscript:

class Data{
int y;
};

void Initialize(Ablity @Ab){
Data @x = Data();
Ab.SetDataObject(x);
};

void Update(Ability @Ab){
Data @x = @Ab.GetDataObject();
x.y = 100;
};

obviously not exact, but it's what i'd like to achieve. (essentially script creates class, hands it to the engine to store, and then pulls it out as it needs it. but the engine has zero idea what the class looks like.) I'm fairly certain the generic handler can achieve this, i just don't know how to register my engine to support this setup.

### #1slicer4ever

Posted 13 June 2013 - 11:15 PM

The memory for the script class is not meant to be allocated manually by the application. The script engine must allocate and initialize the memory. A script class doesn't just contain the members declared by the script, there are also hidden data (object type, ref counter, etc) that the application shouldn't manipulate directly.

May I ask why you want to do something like this? Perhaps there is another way.

thanks for the response Andreas=-)
this is basically what i'm attempting to achieve. my game has a generic "Ability" class, what i'd like to do is use angelscript to manage what an ability does, this means different scripts, have different needs. in the past, i wrote a generic container(essentially a dictionary add-on), that got attached to each instance of the class, and the script could customize that container as it needed. the problem with this approach was doing the look-ups into the container to get the appropriate information the script needs.

I was hoping that their would be a way to directly map memory that the script needs to some class, so that i could store a pointer to the scripts unique class in the c++ ability object.

basically, i want to create an instance of a class(this class is unique to each script), attach it to the ability object, and then when the ability is passed to a generic "update" function in the script, it can pull the custom class pointer from the ability object, and i don't have to do any ugly look-ups to continue working/evaluating what an ability is doing.

i think it'd look like this in angelscript:


class Data{
int y;
};

void Initialize(Ablity @Ab){
Data @x = Data();
Ab.SetDataObject(x);
};

void Update(Ability @Ab){
Data @x = @Ab.GetDataObject();
x.y = 100;
};

obviously not exact, but it's what i'd like to achieve.

PARTNERS