Storing additional properties

View previous topic View next topic Go down

Storing additional properties

Post  mordenkaim on Wed Sep 16, 2009 5:41 am

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. Smile

mordenkaim

Posts : 21
Join date : 2009-05-19

View user profile

Back to top Go down

Re: Storing additional properties

Post  oioioi on Wed Sep 16, 2009 9:56 am

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

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

View user profile

Back to top Go down

Re: Storing additional properties

Post  mordenkaim on Wed Sep 16, 2009 10:00 am

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

View user profile

Back to top Go down

Re: Storing additional properties

Post  sio2interactive on Wed Sep 16, 2009 11:07 am

Simply use the _SIO2object->userdata property.

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 38
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: Storing additional properties

Post  mordenkaim on Wed Sep 16, 2009 11:52 am

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

View user profile

Back to top Go down

Re: Storing additional properties

Post  mordenkaim on Wed Sep 16, 2009 5:38 pm

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.

mordenkaim

Posts : 21
Join date : 2009-05-19

View user profile

Back to top Go down

Re: Storing additional properties

Post  sio2interactive on Wed Sep 16, 2009 5:43 pm

Basic C 101...

objInfo *info;
SIO2object->userdata = info;
info = (objInfo *)SIO2object->userdata;

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 38
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: Storing additional properties

Post  mordenkaim on Wed Sep 16, 2009 5:48 pm

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

View user profile

Back to top Go down

Re: Storing additional properties

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum