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...
remstart
ID Generation. Thoughts and Functionality
Purpose: Everytime we build a visual object we need to assign an id to it, this is an integer value.
But on runtime visual objects need to be created and destroyed dynamicaly.
This needs a system to assign id's and not run out of numbers.
Usage: every time a stage is setup we need to create a group of objects and them manipulate them.
call the pf_getNextID(ai_group) on the creation of each object in array man.
remend
DIM glb_nextGroupID(20,1):` Array Declaration with initial values.
glb_nextGroupID(0,0) = 0 :` objects start from 1
glb_nextGroupID(1,0) = 100 :` objects start from 101 etc.
glb_nextGroupID(2,0) = 200 :` i.e:
glb_nextGroupID(3,0) = 300 :` Mainly only 100 object per group are allowed
glb_nextGroupID(4,0) = 400 :` for now anyway, we can always increase them by altering
glb_nextGroupID(5,0) = 500 :` these values at any time since the set ID resets the start
glb_nextGroupID(6,0) = 600 :` values automaticaly.
` ****************************************************************************************
` those are pf or private functions because we
` only use them from the next level of array man functions
` the main game module will not know about it and wont need to call these functions.
`
` Please Note that I use:
` glb_nextGroupID(ai_group,0) is the start id for each group used for reset only.
` glb_nextGroupID(ai_group,1) is the next id for each group
` ****************************************************************************************
function pf_resetAllGroupId()
`big reset. make all next ids the initial value again
for li_group = 1 to 20
pf_resetNextID(li_group)
next li_group
endfunction
function pf_resetNextID(ai_group)
`small reset. make a next id the initial value again
glb_nextGroupID(ai_group,1) = glb_nextGroupID(ai_group,0)
endfunction
function pf_getNextID(ai_group)
`get the next available ID
li_id = glb_nextGroupID(ai_group, 1) + 1
glb_nextGroupID(ai_group,1) = li_id
endfunction li_id
I hope people will learn from this thread the mechanics of the game structure...
-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy