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.

Dark GDK / Will dark sdk safely ignore media id 0?

Author
Message
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jul 2006 13:52 Edited at: 19th Jul 2006 13:54
I always found it a little unsettling how dark sdk wont give you any kind of warning/crash if you try and use 0 as a media id. In dbpro if you tyed to 'position object 0' or 'hide object 0' the program would crash. So are we 100% sure that ALL the commands will safely ignore '0'?

I wrote a test program and listed as many commands as I could think of off the top of my head, everything LOOKED ok.. would be nice to get a confirmation though.

* it also bugs me how bad/corrupted files (objects, images) will still 'load' with no warning. Or they might not load at all if you spell the filename wrong, then what happens when you try and POSITION the object you thought you just loaded..

All you need is zeal
Sephnroth
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 19th Jul 2006 17:21
iirc one of the things that the sdk (and indeed, dbp) really lacks is return values. its a bugger because it makes debugging hard. But its very easy to write your own so why dont you? ie, try this:


and walla, error checking. you could use it like:



you can do the same thing for images using dbImageExist, etc. hope thats usful

CattleRustler
Retired Moderator
20
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Jul 2006 21:02
it would probably be faster to have the caller code check its own iID var. Since id's lower than 1 make no sense maybe just:

'iID is the passed in, intended, Object Number

if iID > 0 then....
'do whatever
end if

instead of asking dbp/dgdk to iterate its objects
just a suggestion

Science, Mathematics, and Physics do not lie - only people do.
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 19th Jul 2006 21:05
Probably be best to do both - that way you wont get problems if you use the same ID number twice.

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Dont do anything I wouldn't do. But if you do, take pictures.
Barnski
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: Switzerland, Zurich
Posted: 19th Jul 2006 21:57 Edited at: 19th Jul 2006 21:58
Speaking of refining the function to use when loading objects, you can go further and define a function that returns an obj_id, such that you have a dynamic system.

However, I don't do it this way, but with a ressource manager with which it is also possible to "reserve" a range of ids, for lets say everything to do with your menu, or everything with a map.
Doing that you can easily use the faster deleteObjects command, which deletes objects within a id range.

If you have only one location in your code that is responsible to use the correct object id (in the ressource manager) it is easier to keep it bugfree, without having to worry about having wrong object ids. The problem of an error when loading could be caught by the res_manager too, you d just need to ask him if an error occurred.

Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 20th Jul 2006 03:38 Edited at: 20th Jul 2006 03:44
Thanks for the advice guys, ill definitely make some kind of 'extended' version for all my 'media loading' commands (one that verifies the object was created, and returns the media id would be very helpful). But what about the position, hide, ect... It would be a PAIN to write a special command for all those, can we assume at least THOSE will be safe with media id 0?

Although, if I do my loading functions properly, I should never have a media id 0 to worry about anyway.. hehe.

All you need is zeal
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 20th Jul 2006 07:37 Edited at: 20th Jul 2006 07:49
Well I wrote this nifty little function for my object loading...



It will auto find a available media id, load the file, and then return the media id. If there are no free media ids, or the file has trouble loading, you get a little warning box and the return value is 0 (so it shouldnt screw up anything if you try and position the object, ect...).

Now I gotta make one of these for images, meshes, ect... I got my night planned!

*edit and btw, I tryed loading a 'bad' file for my terrain objects, just to see what would happen, and everything seemed to run just fine! The terrain object didnt display obviously, but because my 'super happy Ex' function returned a media id of 0, things didnt crash, even when doing about everything under the sun to a '0' object (positioning, hiding limbs, texturing, manipulating all the vertex data, ect).

All you need is zeal

Login to post a reply

Server time is: 2024-05-18 21:43:34
Your offset time is: 2024-05-18 21:43:34