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.

Newcomers DBPro Corner / Assigning IDs on Runtime

Author
Message
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 10th Sep 2003 19:13
Early in the development of my masterpiece I realized I need a system to get id on runtime.

The main Idea is that I dont think it is possible to start creating object and 'hardcode' their id's and then call this object effeciently on different modules of your project. Especialy when you need to manage and 'direct' to coin a phrase from the film industry who knows how many more...

So I thought, what if I create groups of objects and assign them to arrays and deal with the arrays instead.

Here is my next ID generator, and please do comment on my approach, if you have a better way to do it please enlight me, if not them please let me know if I am on the right path...

My entry is in the form of pseudo code (not miles away from the real deal) with lots of documentation.

Enjoy...



I hope people will learn from this thread the mechanics of the game structure...

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 11th Sep 2003 01:36
You have a design issue and until you make it a problem you don't have the solution.

In regards to my previous post, I have a new approach ...

Problem
I decided to make a game by assigning objects to arrays. But every object has to have an ID to be referenced by. I do not want to create an object and give it a number myself, not because I am lazy but because I do not want to keep a pile of paper and PostIts on my desk with ID's I used.
Plus it is impractical, to say the least, when objects are created dynamicaly and randomly. All these objects need to have an ID tho...

Solution
So here is my solution to the problem:



Usage:
When I create a visual object I do a li_id = pf_getID()
So Get ID assigns a dissused or a new ID.

When I destroy an object I do pf_saveid(li_id)
So I get the ID of the object I just destroyed and save it in case there is a new object in the future that will need an id.

Notes:
Note that position 0 in a array is a place with I keep the max number of objects available.

Please have in mind that I have functions that create and destroy certain types of visual objects. But this is something you have to decide how to do in your game based on your game needs.

After all it is something I still fight with and redesign all the time but this technique is what I came up with and I hope it will help you and even prompt you to let me know what else can it be done or any more ideas that i should consider????

Any questions please do ask! any comments please do make!



-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 11th Sep 2003 01:42
OOPS

and here is one more line I forgot in my code.

glb_nextid(1) = li_id inside the part where it makes a new ID. We need to keep on increasing the new ID generator to avoid conflict and this line saves the new id back to the array doing just that.

Still here is the complete code again:


Sorry for the error...

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy

Login to post a reply

Server time is: 2024-09-20 21:30:24
Your offset time is: 2024-09-20 21:30:24