Storing additional properties
3 posters
Storing additional properties
I would like to tie properties to a SIO2object directly. I really just want to add 3 unsigned int variables to them to keep track of a few object states. Is there any functionality built in to maintain properties on a specific SIO2object or should I just add the properties into the SIO2object object itself? My other option would be to maintain a separate array of unsigned ints to keep track of them. The downside to this is I will be moving the SIO2objects around in another array and I don't really want to have to manage 4 seperate arrays when I could just have the properties attached to the objects themselves. Does anyone have any advice on the best method to go about this? Thanks in advance.
mordenkaim- Posts : 21
Join date : 2009-05-19
Re: Storing additional properties
The easiest way to do this is just add the variables to SIO2object, but if you work on several projects you might not want those extra variables in all projects, only 3 ints won't make much difference.
Another way to go is creating a new structure whit the extra variables and a pointer to the SIO2object. That's what I do for enemies in my game, but they have a lot more extra variables than just 3
Another way to go is creating a new structure whit the extra variables and a pointer to the SIO2object. That's what I do for enemies in my game, but they have a lot more extra variables than just 3
oioioi- Posts : 136
Join date : 2008-12-02
Location : Norway
Re: Storing additional properties
Thanks! I might go ahead and do it with the struct in case I decide later I need more information then that tied to the objects.
mordenkaim- Posts : 21
Join date : 2009-05-19
Re: Storing additional properties
sio2interactive wrote:Simply use the _SIO2object->userdata property.
Very nice. I had a hunch you would have built something in for this. Thanks!
mordenkaim- Posts : 21
Join date : 2009-05-19
Re: Storing additional properties
Hmm, trying to use the userdata property. Is there a good example? I'm trying to cast the variable in and out. I've created a structure and I'm trying to set it to the userdata property of an SIO2object.
objInfo is the structure I've defined.
objInfo *info;
SIO2object->userdata = info; //this works...
info = (objInfo)SIO2object->userdata; //this doesn't work...
I was thinking the void pointer would allow me to set it to whatever type is necessary then I could just retrieve it by casting.
objInfo is the structure I've defined.
objInfo *info;
SIO2object->userdata = info; //this works...
info = (objInfo)SIO2object->userdata; //this doesn't work...
I was thinking the void pointer would allow me to set it to whatever type is necessary then I could just retrieve it by casting.
mordenkaim- Posts : 21
Join date : 2009-05-19
Re: Storing additional properties
Basic C 101...
objInfo *info;
SIO2object->userdata = info;
info = (objInfo *)SIO2object->userdata;
objInfo *info;
SIO2object->userdata = info;
info = (objInfo *)SIO2object->userdata;
Re: Storing additional properties
Thanks again... pointers have always been my weak point. Java was my first language. Sorry for the noob question.
mordenkaim- Posts : 21
Join date : 2009-05-19
Similar topics
» Loading Additional Object At Runtime
» soft bodies properties question
» Best Practice for an Object with Variable Material Properties
» soft bodies properties question
» Best Practice for an Object with Variable Material Properties
Permissions in this forum:
You cannot reply to topics in this forum