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 / types and user defined types, little help please

Author
Message
Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 27th Oct 2012 17:09
Ok just like the title says! I hope I don't sound dumb here. I have read about them in a book, done searches on the forum and somewhat have a small understanding but a lot of the time books are hard to understand so could someone give a quick explanation in easy to understand words?

what is the purpose? how used, when to use, ways to use etc...

Thanks
Dragonslayer
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Oct 2012 17:21
http://forum.thegamecreators.com/?m=forum_view&t=110324&b=7

That might help. Use them all the time and wherever possible. They help create a hierarchy in your program and it helps a great deal to structure your code much more.

TheComet

- The codebase
Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 27th Oct 2012 17:50
Well that helped some. I will keep digging into it!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Oct 2012 18:13
Also, a small tip that not many know of, you can have types inside types as well:



As you can see, very structured.

TheComet

- The codebase
Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 27th Oct 2012 19:05
Yes I knew that but thanks for the code snippet. It will give me something to study and go by!

I hate to be a pain in the ass but I started a piece of code and need to know if it is somewhat correct.



I kind of went by some code comet showed me. The tile type are as integer and a constant such as grasstile = 0 so when placing them in the array do I have to write out

Faa(0,1).TileType = GrassTile? what is the purpose of the numbers by each tile type?

Why can't it be like this?

Faa(0,1).TileType = 2

Also I am figuring of all of these tiles I may want a building type so this may be where I can do a type inside of a type. would that be right or should I make the building type separate?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Oct 2012 19:31
First of all, constants need to be outside type definitions.



Secondly, populating the array can be done much less painfully. Here's a method using data statements (although this is a little more structured, it's still pretty painful to edit your map):



Your best bet is to create a simple level editor which saves your maps to a file. The file can then be loaded and fill the map array.

TheComet

- The codebase
Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 28th Oct 2012 01:19
If I knew how to do a level editor I would. I am very new at programming even though I have been around here a long time. I am pretty sure I am thinking too far ahead. I think I need to take much smaller steps.

I changed it around, populated the array with about 6 elements and tried to print one out and could not even get it to print. I am thinking about getting back into the Hands on DBP vol 1 book. That gets quite boring. Maybe when it tells me to make a certain program for the stuff I just learned I can make the program but make it with what I want in it, something relating to a game out of my head. Maybe then it will not be so boring.
The Weeping Corpse
14
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 28th Oct 2012 01:33
Just found out that UDT's can't contain arrays. Why Lee? Why?

THIS is a massive pain in the ass and my program is turning into spaghetti code.



/RANT

Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 28th Oct 2012 01:41
No but I think you can make one outside the udt and use what you defined in the udt in the array. Not real sure I must learn more.
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 28th Oct 2012 02:35
Quote: "THIS is a massive pain in the ass and my program is turning into spaghetti code."

That reason is the #1 reason I most most of my active development to C++. Classes/structs are awesome compared to UDTs.

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 28th Oct 2012 10:27
I heard that there was a work around, using pointers, to get around the limitation of being unable to use arrays within a UDT. I believe that Ian's Matrix1 Utilities had to be used.

Could someone post an example if they've got one handy?

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia

Login to post a reply

Server time is: 2026-07-10 09:48:57
Your offset time is: 2026-07-10 09:48:57