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.

DarkBASIC Professional Discussion / question on item numbers

Author
Message
Disrupter52
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 6th Jun 2011 05:07
Hey everyone.

Going through some DBPro tuts and ive noticed that (so far and maybe) the only way for you to identify different objects (be it a sphere, matrix, texture etc) is via the number you assign it upon creation.



That code makes a cube and that cube is known to DBP as "1". So if you wanna do stuff you call it as 1.

Is there any way to change it so you call it as a name rather then a number? How would you keep track of hundreds of items if theyre all by number? It doesnt make too much sense to limit it like that.
DarkByNight
16
Years of Service
User Offline
Joined: 16th Jul 2009
Location: Thailand
Posted: 6th Jun 2011 05:19
From my limited graphical programming I am fairly certain you would you something like this:

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 6th Jun 2011 06:48 Edited at: 6th Jun 2011 07:06
With bigger, more adaptable projects, you have fewer constants and more variables. So, if I was coding something, and I wanted to insert something into a player's inventory, i'd write a function that might look like this:


That code has 0 constants. Whenever I wanted to add something to the user's inventory I know I'd just have to say "addToInventory(fireballspell)" or what not.
If I was making a game about zombies, and I wanted to create another zombie, I'd say something like:



It's not specially limiting if you have to number everything. I don't see how naming would solve the problem of keeping track of hundreds of objects. Would you have "Zombie_number_one" and "Zombie_number_two", etc? 1,2,3,4, is - in my opinion - way more concise.

I program so that I don't have to keep track of anything, my program keeps track of it all. (in the above examples, I used variables, arrays, and UDTs)


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Jun 2011 14:52
I tend to use constants only for something that will not change in my code such as the object number for my player object.

For something there might be lots of such as asteroids or generally simple items I would just create a simple array

For more complicated objects such as characters / zombies I would use UDT arrays as suggested by Neuro Fuzzy.

A UDT array can be defined like this:


That's just an example of how you set one up to be used as NF suggested "zombieArray(index).objnum"...

Hope that helps

Disrupter52
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 6th Jun 2011 15:54
alright thanks guys, ill keep these tips and tricks in mind.

Login to post a reply

Server time is: 2026-07-10 14:05:27
Your offset time is: 2026-07-10 14:05:27