RequestID()
BlitzMax Forums/BlitzMax Programming/RequestID()
| ||
Yes, we need this! Why? Regulary I'm creating event-based code, usually gadget-related. Since I need my own event id's to have it al working I need to keep track of free ID numbers. Usually all my own events start with 1337, then followed by some obscure 0666 number orso. :P But it would be perfect if there was this RequestID() function that simply keeps track of a list of used EventID's, the BRL ones and even your own ones. So, the only thing you'd have to do when creating an event id is doing: Global EVENT_COLORCHANGED:int=RequestID() Global EVENT_COLORCHANGING:int=RequestID() Global EVENT_BUTTONPRESSED:int=RequestID() Global EVENT_PALETTECHANGED:int=RequestID() etc. Kinda like enum except that you don't need to know which ID's are in use already. This list of IDs should prolly be an object with a list inside, so this RequestID() function would know where to look for used eventIDs. A function like this would save me from searching through all my files to check if I don't overwrite some ID (let alone BRL introducing a new ID on a position *I* was already using for my own stuff!). Also, it's portable across users who have their own list! |
| ||
I generally use an MD5 hash of millisecs + some random thingie. |
| ||
Yep, and asked for the same some time ago. AllocHoodId works with a global array of 256 numbers farming out the next number each time. You could do the same making the first number 'safe' i.e. > 32769 but you can't guarantee they won't be used again in the future. or 0-255 which are not currently used. |
| ||
Even when using a safe number, you'd still have to check on your own ID's being overwritten, and your code would still not be truly portable. |
| ||
True your code won't be portable but you wouldn't overwrite if you keep the safe numbers in an array plus a pointer to the next one to use. Alternatively, use a number like Indie suggests. |