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 / Can you give objects String ID's?

Author
Message
superman3275
13
Years of Service
User Offline
Joined: 8th Feb 2013
Location:
Posted: 9th Feb 2013 06:58
On every tutorial I've looked up, you create objects and give them an "ID". Coming from C++, this feature seems extremely hard to manage. Objects can't have meaningful names and telling the difference between them is complicated. One work-around is creating a user-defined type which holds the object and accessing the object through the user defined type. However even then, your code quickly gets Messy. Is there any way to give an object a string ID rather than a number?

Cheers !

I can program in C++ and SFML 2.0, JavaScript, HTML5 / CSS3, and DarkBASIC Professional! Fear Me !
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Feb 2013 17:08
I must question your decision to move to a more primitive language, but that's beside the point.

The easiest option would be to use constants (known as #define in C++):



Unfortunately, DBP doesn't support enumerators or anything fancy like that, so you'll have to manually define each object ID as you go.

The other more complex method would be to make yourself a function that handles a small database of object strings and object IDs. It could be implemented like this:



And later on you would access it like this:



The way you implement it is up to you.

TheComet

http://blankflankstudios.tumblr.com/
"ZIP files are such a retarded format!" - Phaelax
Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 9th Feb 2013 17:19 Edited at: 9th Feb 2013 17:19
I made a tutorial a while back that may be of interest to you.

http://forum.thegamecreators.com/?m=forum_view&t=115298&b=1

"everyone forgets a semi-colon sometimes." - Phaelax
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 9th Feb 2013 17:27


Advanced Updater for your games!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Feb 2013 18:26
Is TheComet's avatar on speed? Looks like at any minute Rainbow Dash is gonna fly through my screen and turn Super Saiyan!
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 10th Feb 2013 07:31
Quote: "Is TheComet's avatar on speed? Looks like at any minute Rainbow Dash is gonna fly through my screen and turn Super Saiyan!"


Turn of the 3D Glasses

Advanced Updater for your games!
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 10th Feb 2013 13:11
I do this:



Loading code:


Regards Sph!nx
www.mental-image.net
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 10th Feb 2013 19:42 Edited at: 10th Feb 2013 19:54
that just picks an unused number, it doesnt match the object to a name as string in any way, you cant later reference a particular object by 'object#' because that variable will only give you the last object created.

i usually just store the obj number as part of a udt, for meaningful objects, you will need a udt to store a variety of other information anyways. position, state, attributes etc



you can then iterate the array to process all character objects, or to find a specific one by name

general scene objects like buildings, rocks, trees, etc dont really need names, especially if you do nothing with them beyond loading. for things you need to go back and animate like trees mabye, you can just add them to an array of integers: trees(0) and iterate through by index with no need for names.

Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 10th Feb 2013 19:56
If speed is the most important thing in your project, you need to reference object numbers directly, as TheComet says above:

#constant PLAYER_OBJECT 1
#constant ENEMY_OBJECT 2

During compilation, any references to PLAYER_OBJECT, for example, will be replaced with 1.

A call to a function like this:

yrotate object GetObjNum("EnemyShip"),object angle y(GetObjNum("EnemyShip"))+1

will slow your program down because GetObjNum is being executed twice in this single command. If you do this in every iteration of your main loop, for many objects, the speed difference will be noticeable.

HTH,

James
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 10th Feb 2013 20:10 Edited at: 10th Feb 2013 20:18
in such a usage you can call the get function once at the start and set to a variable, then you can replace all subsequent calls to the get function with the vriable to speed things up.



better still, by tracking the angle data in a udt, you can also eliminate the call to object angle y and similar for further speed gains



while using the constants is faster its really not practical for a large number of objects, and makes the project rather inflexible.

Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 10th Feb 2013 21:14
@ Ortu: there is no need to rewrite my reply.

Advanced Updater for your games!
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 10th Feb 2013 22:15 Edited at: 10th Feb 2013 22:35
well i hadnt read your reply since it was just a lengthy block of code with no actual reply text to tell what it was about. additionally, i was replying to posts well after yours which were still discussing the subject, as your post didnt settle and end the thread, further discussion is still valid.

edit, sorry i don't mean to bristle, no one is trying to steal your thunder, i'm just here to help the same as you are, my replies to posted questions really had nothing to do with you in any way.

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Feb 2013 22:29 Edited at: 10th Feb 2013 22:31
@superman3275

You can name your objects with strings like so:


If you want to create a dictionary (string lookup); you can use one of the following Key/Value pair solutions:


or



or



Like with all dictionary references they will be slower than direct ones. DBPRO does not have a dictionary system, so you have to make one if it is important. Frankly, I can't see the problem with simply using UDTs to store object references. If you are using a good IDE like Indigo, then organizing objects into types and autocompleting references should be straight forward.

@Sph!nx
Quote: "object# = find free object()
load object "object.x", object#"


You should use integers or DWords for IDs; an object ID does not need a decimal point, and the conversion will slow things down

Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 10th Feb 2013 22:40
Quote: "You can name your objects with strings like so: "


neat! ive worked with limb names like handR to glue a weapon but never thought of naming limb 0 for the object as a whole

Login to post a reply

Server time is: 2026-07-07 02:39:02
Your offset time is: 2026-07-07 02:39:02