Jump to content
  • Advertisement
hiago desena

Script classes nested GetAdressOfProperty

Recommended Posts

I couldnt find any example of this so im wondering if you support in angelscript.

So the scenerio is that I have these two script classes.

Class B

{

int IntValue;

float FloatValue;

}

 

class A

{

 class B;

}

 

So class "A" is my scriptObject that i then perform the GetPropertyCount. I iterate through each property (There is only one)

And I do GetAddressOfProperty which returns me a void* to class "B". Now i have the type information for class B, so I then want to iterate through each property information for 

class "B". Is there a way through the API for me to access the address of that "A.B.IntValue". ?? If you have any questions let me know

Share this post


Link to post
Share on other sites
Advertisement

Not sure your class A is correct.
You just seem to have a "class B;" declaration of a class "B" existance. Did you forget to create an actual member field?
I think "GetAddressOfProperty" will get you the address of the field, so if you have field that is a pointer to B, the return value will probably be a pointer to a pointer to B.
If you have a pointer to B, you can cast the pointer to "asIScriptObject" and use the same "GetAddressOfProperty" to get the address of "IntValue" inside an instance of B

Share this post


Link to post
Share on other sites
Posted (edited)

I thought i was clear. Im sorry this is better:

 

Class B

{

int IntValue;

float FloatValue;

}

 

class A

{

   B mValue;

}

 

Where class A has a instance of B instead of it that is NOT a pointer, but is by value.

The issue is that both these classes within a script are defined solely on angelscript side so in C++ im only working with the void* to the address.

Edited by hiago desena

Share this post


Link to post
Share on other sites

I think you'll still find that "GetAddressOfProperty" will return a pointer to a pointer to B.
If you haven't seen the docs about different object types, you can find it here:
https://www.angelcode.com/angelscript/sdk/docs/manual/doc_datatypes_obj.html
The important bits are
"There are two forms of objects, reference types and value types."
"Only the application can register these [value] types"

(It's like "class" and "struct" in c#: one is always a pointer the other is always a value)

Class B being a reference type will be represented as a pointer inside class A.
What problems are you having?
Did you check that you are getting the right propety?
asIScriptObject might have hidden properties and your's might not end up with index 0.

You should be able to just run

asIScriptObject* classBInstance = *static_cast<asIScriptObject**>(asIScriptObjectOfA->GetAddressOfProperty(indexOfMValueProperty));

*static_cast<int*>(classBInstance->GetAddressOfProperty(indexOfIntValue)) = 777;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!