Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [Request] User data

Author
Message
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 6th Nov 2012 17:17
I keep my sprites in arrays, when testing for a sprite hit it is often required that you need the index of its position in the array.

Obviously the user creates the array so there is no way of AppGameKit knowing this value. I think it would be a good idea for a sprite(and other entities) to hold perhaps 16 integer values that the user can set, these could represent index values in user created arrays.



At the moment I need to loop through the array each time, comparing the sprite ID to find its index.

If anyone has a better way of working then let me know.

MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 7th Nov 2012 00:01
what about an hash or associative array?
http://en.wikipedia.org/wiki/Hash_function
For example (like in Perl, PHP or other languages):

Unfortunaly HASH type does not exist at the moment. Workaround could be to implement yourself an hash function or to ask TGC to implement hash construct.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 7th Nov 2012 01:14 Edited at: 7th Nov 2012 01:17
That would also be a solution although not as easy to use.

Another use would be that each integer(32bit) could potentially hold 32 user created boolean values. When I realised there was no GetVirtualButtonIsVisible() command, I had to create an array of booleans to hold this information for me, what a pain . With user data I could have just designated a single bit to hold this information for me.

User data is pretty common in various SDKs.

That said, it's not a high priority for me since my game is nearly done and I will probably try tier 2 for my next game, partially because of this limitation.

EDIT: For tier two I would request a void pointer instead, the user data could be anything you like then.

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 7th Nov 2012 15:38
Quote: "At the moment I need to loop through the array each time, comparing the sprite ID to find its index."

That how I always do it! It can be a bit slow though when dealing with many sprites, particularly if you have to check two groups of sprites. I haven't played much with them, but aren't the get sprite group commands used for this sort of thing?

AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 22nd Nov 2012 05:46
I too have had several occations where sprite "user data" would have allowed for creating much faster code, when doing table lookups for additional information about sprites tied to an array of user defined data types.

Sprite groups are very useful, and can save a lot of code - but they should not be used to encode user data. If sprite groups are used to encode the userdata that we need a sprite to contain, then we pretty much give up the ability to use the groups for their original purpose - and there are cases when a program needs both sprite groups AND user data.

I added a feature request stub for this post on the AppGameKit issues list. Feel free to fill it in with more information. (The feature request also links back to this forum thread.)
[FEATURE REQUEST] TIER 1 - User data storage within sprites

Cheers,
AgentSam
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Nov 2012 10:46
That would be very useful indeed. I'm not sure how much quicker it would make my games as they seem to run fine doing things the way it has to currently be done but it would certainly tidy up a lot of code!


this.mess = abs(sin(times#))
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 22nd Nov 2012 13:43
One of the (many) nice things about Delphi is that almost all objects have a Tag field, which you can use for any purpose. As mentioned early, if you set the Tag to the object's index in an array, if it's clicked or whatever it's easy to (for example) relate it to a list or other object.

So I would vote definitely for it.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL

Login to post a reply

Server time is: 2024-05-05 21:34:34
Your offset time is: 2024-05-05 21:34:34