🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Script classes nested GetAdressOfProperty

Started by
4 comments, last by WitchLord 4 years, 11 months ago

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

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

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.

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;

You may also want to take a look at the article on 'reflection' in the manual.

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

This topic is closed to new replies.

Advertisement