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 / DBPro with User-Defined Datatypes

Author
Message
anwserman
15
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 24th Jun 2011 14:48 Edited at: 24th Jun 2011 14:50
Ok, I've searched the forums and have noticed a couple shortcomings with DarkBasic pro and using user-defined datatypes.

1) UDT cannot directly be passed as a parameter in a function, if they're also a part of an array
2) You cannot use a UDT as a return value from a function, without a workaround
3) UDT cannot contain arrays, without a workaround.

These three problems have definitely made me think outside of the box in regards to my programming. However, I cannot get past this shaking feeling that my code is becoming bloated, inefficient, and just plain horrible

As quick rundown of my program....

a) Multiple people in the level
b) Each person casts four vectors for collision detection
c) Each vector consists of two points
d) Each point consists of three values (X,Y,Z)

I come from the world of object-oriented programming, and this screams using UDT's and arrays to store these data types. But, I cannot easily manipulate UDT's in functions, as there are limitations passing them in, and they cannot be returned without a hackjob. Which in itself could lead to buggy code. I could have duplicate code, which would solve that problem, but duplicate code leads to its own issues.

So, I'm confused. I'm relatively new to DarkBasic (hence all the newbie posts!) but I'm still extremely excited about using the product. In the week or so that I've been programming, I've exceeded what would take months to do in other SDK's that I have used.

But, for the sake of good design code, and not wanting to rewrite huge chunks later on - what good design tips are there for dealing with data situations like this?

EDIT: To show a small portion of what I have so far....
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jun 2011 15:10 Edited at: 24th Jun 2011 15:12
That all looks OK so far. Now all you have to do in your functions is pass the array element. The array is global, so the function can see it.



GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 24th Jun 2011 17:27
I also am coming from a heavy OOP background. But way back in the day I learned how to program in Basic.

You can do certain things to organize your code, but at the end of the day, your game code is gonna look like Copypasta aka Spaghetti code. Knowing that keep your programs simple.

The key here is spend a day elminating that idea of "Code Reuse" that OOP forces on you. Each and every basic program is going to be a one off thing. Then use the power of Gosub and Return to hook all your various programs together.

But I offer all of this on a contingency bases... I have been using DBPro for exactly one day.

For what it is worth, I spent a year trying to put together a game in XNA, and rather than having spaghetti code, with XNA you wind up with a sea of objects floating in a list, and sorting out a few misbehaving objects in that mess makes working through spaghetti look simple.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 24th Jun 2011 19:28 Edited at: 24th Jun 2011 19:30
Quote: "The key here is spend a day eliminating that idea of "Code Reuse" that OOP forces on you."

I whole heartily disagree with you there! All my programs are designed so that modular functions can be plugged in via their own include file which contains all the needed variable declarations, and all functions automatically initialise themselves. The perfect example of code reuse right there. I can take one addin file, (for example the water shader plugin) and everything I need to create shader water is included in that file. One call to the "CreateWater" function and BAM! Shader water which can be plugged into any program I want without ANY additional coding changes.

Quote: "Then use the power of Gosub and Return to hook all your various programs together."

I whole heartily disagree with you there! Gosub/return forces you to keep all your code in one giant routine with no local/global variable scope. See my above answer as to what I believe to be the one true approach to modular coding in a procedural language.

My signature is NOT a moderator plaything! Stop changing it!
GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 24th Jun 2011 21:55
Well lets agree to disagree.

I like Global variables for smallish programs (say < 10k lines of code). DarkBasic seems to have a lot of emphasis on global variables... All game objects are in a couple of different global arrays/lists. All arrays are global. There is a lot of emphasis on global identifiers in DarkBasic.

Private identifiers do have their place... But I don't see the difference it would make by putting your CreateWater function in a subroutine instead, and then just including it in your program, then adding Gosub _CreatWater to your program...
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jun 2011 22:29
Quote: "The key here is spend a day elminating that idea of "Code Reuse" that OOP forces on you. Each and every basic program is going to be a one off thing"


That's definitely not the case. I have my own library of DBP functions that mean I can make a menu with multiple levels, bitmap font dynamic options, fade in and out, and mouse over effects (including fade, scale rotate and position) all in about 10 lines of code. I can load and sequence multiple sound effects, automatically generate screen resolution options, display a high score entry keyboard and create a HUD in just a few lines each. All of these are supported by self-contained modular functions.

Quote: "use the power of Gosub and Return to hook all your various programs together"

If you use functions, then you can use local variables. Gosub vs Functions is personal preference, I never use any Gosubs myself.

Login to post a reply

Server time is: 2026-07-11 03:38:39
Your offset time is: 2026-07-11 03:38:39