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 / keeping track of objects

Author
Message
wizard
21
Years of Service
User Offline
Joined: 23rd Oct 2003
Location: CANADA
Posted: 28th Oct 2003 00:02
I was wondering what is the best approach to keeping track of many object numbers in a large prog?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 28th Oct 2003 00:40
best answer I can give is think it thru before you write the code, and keep a list on paper or as comments in code. Unfortunately dbp has no way of iterating thru each of the object types and returning what the object "is" - like you would in a "Collection" in other languages.

if there is a way in dbp I would like to know it.

-RUST-
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 28th Oct 2003 01:21
Follow the link to my thread. It has my "object naming library." For DBC, untested in DBPro.

http://darkbasic.thegamecreators.com/?m=forum_view&t=19194&b=6
wizard
21
Years of Service
User Offline
Joined: 23rd Oct 2003
Location: CANADA
Posted: 28th Oct 2003 16:32
Hey nice job! Thanks for your reply!
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 28th Oct 2003 21:34 Edited at: 28th Oct 2003 21:38
My personal approach is to use a variable name (same name as object but beginning with "o_")with the objects number in it.
Here is a quick copy/paste from my current project to give you an idea of what I mean:

load object "modelsship1.x",10:o_ship1=10
load object "modelsship2.x",20:o_ship2=20
load object "modelsship3.x",30:o_ship3=30
load object "modelsship4.x",40:o_ship4=40
load object "modelsLanding pad.x",50:o_landingpad=50
load object "modelsradar.x",55:o_radar=55
load object "modelsradarbase.x",60:o_radarbase=60

Now if I want to rotate the object called 'radar' instead of remembering that radar is object number 55 I simply use:
ROTATE OBJECT o_radar,x,y,z

Hope that helps.
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 28th Oct 2003 22:42
I posted a snippet in the code snippets forum that writes all the object number, image number, sprite numer, matrix number, sound number and music numbers all to a .txt file.

RPGamer

Current Project: Eternal Destiny WEBSITE SOON!
"Thats not a bug! Its a feature!" - _ESC
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 28th Oct 2003 22:43


Just stick that after you load/create anything....

RPGamer

Current Project: Eternal Destiny WEBSITE SOON!
"Thats not a bug! Its a feature!" - _ESC
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 28th Oct 2003 23:37
why the 100 cut off?

-RUST-
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 29th Oct 2003 18:12
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
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 29th Oct 2003 19:39
if you want a function to see a variable that is declared outside of the function, declare it as Global

Global intMyVar as Integer

-RUST-

Login to post a reply

Server time is: 2024-11-25 14:43:25
Your offset time is: 2024-11-25 14:43:25