I tend to use a lot of functions and as you know if you declare a variable on one function or even the main program loop you can not reference it from another.
so I use Arrays because they are global. But this uses up lots of resources, being arrays and global!
When I declare a visual object I try not to try to figure out an id for it.
so instead of:
make object cube 501, 50:` from 500 on are my cubes!
I use this:
lo_dice = NextId():` NextID() is a function that I wrote that always return a free int.
make object cube lo_dice, 50:` lo_dice is a local variable, but i use lo_ meaning "Local Object"
But this gives me a problem. How do I refer to this lo_dice in a function?
This is where the think the design through before you start, comes handy.
In the case of the dice, say you have 2 dice.
I would declare and array called dice[] DIM dice[2]
Have a look at this:
`Make first Dice
lo_dice = NextId():` NextID() is a function that I wrote that always return a free int.
make object cube lo_dice, 50:` lo_dice is a local variable, but i use lo_ meaning "Local Object"
dice[1] = lo_dice
`Make second Dice
lo_dice = NextId():` NextID() is a function that I wrote that always return a free int.
make object cube lo_dice, 50:` lo_dice is a local variable, but i use lo_ meaning "Local Object"
dice[2] = lo_dice
A bit repetitive. So you might want to make it a function and make it with a parameter:
function MakeDice(ai_size)
lo_dice = NextId()
make object cube lo_dice, ai_size
endfunction lo_dice
and the all you have to do is:
DIM Dice[2]
dice[1] = MakeDice(50)
dice[2] = MakeDice(50)
From now on all you have to know is that your dice objects are in their nice array and you can throw animate or change 1, 2 or both without remembering the numbers you used.
The key point to all this is the NextID() function... You can ponder on that and make one yourself.
Oh! One thing. I don't have darkbasic here so my examples might not exactly compile!!!
-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy