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 Discussion / How does the TYPE command work?

Author
Message
Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 29th May 2008 03:53 Edited at: 29th May 2008 06:27
I've seen lots of DBPro code use type, and I noticed that it gets highlighted as syntax when I type it in DBC. However, I don't see it in the help files. I did a forum search, but all I got was a code example of it. Can someone please tell me what it does?


The bottom half of your signature was erased by a mod because it involved Kirby.
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 29th May 2008 04:20
Quote: "I've seen lots of DBPro code use type, and I noticed that it gets highlighted as syntax when I type it in DBPro."


Wrong forum, this is the DarkBASIC Classic forum

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 29th May 2008 06:27 Edited at: 29th May 2008 06:27
Ahh! Typo! I meant when I put it in DBC. My bad...


The bottom half of your signature was erased by a mod because it involved Kirby.
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 29th May 2008 07:01
type isn't a command in dbc (obviously). From what I have read it appears to be similar in nature to arrays, but with the added benefit of names. These are similar to structures in C. It lets you, in a way, create your own variable types, the way functions lets you create your own commands.

This is an example I am taking from the DBPro help


Important parts are the type/endtype block, and the AS commands. Specifically DIM Accounts(100) AS AccountEntryType (notice this is the name of the type block). Using types you can make one variable hold several different values (as seen from accounts(1) being used several times with different subscripts that correspond to variables in the type blocks).

Anyway, this is what I deduced, though I feel like I am missing something. Anyone who knows for sure, feel free to correct me.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 29th May 2008 07:15
Types aren't natively supported in DB classic. But, some IDE's like DarkEdit (from memory by Guys) have some limited type support via a pre-parser.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 29th May 2008 07:55
Types are useful for grouping different types of linked variables together. For example, think about all the pieces of information associated with just the player's character in a game.

Each one is stored in a variable so you have variables called Score, Health, Hunger and so on. With other characters you need different variable names. Types let you create all these separate variables in a package and give it a name.

So, think of a Type as being like a record in a database, where each field can be a different type of variable. So, in a Members database for example you might have a Name field (string), an Age field (integer) and a Height field (float).

In DB, the equivalent of this record is the Type. You could call it Members and define the types of all the variables within it.

Accessing the variables within the Type is simply a case of using the Type's name followed by a full stop and then the name of the variable - such as Members.Name or Members.Age.

Another advantage of this is that you can have a many Types - each using the same 'variable' names within it. So Player.Health, Elf.Health, Orc.Health and Ogre.Health make your programs a lot easier to read and follow.

And, as BN2 Productions points out, the ability to create arrays of Types means you can easily store all the info for all the Orcs and elves in your game - regardless of the number.

TDK_Man

Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 30th May 2008 04:13 Edited at: 30th May 2008 04:32
Ah, I get it now. But I'm confused. Are they supported in DBC or not? (sorry if I was a bit harsh on that question).
EDIT: I just tested it; unfortunately they don't work in DBC.


The bottom half of your signature was erased by a mod because it involved Kirby.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th May 2008 09:53
As someone said earlier, types are supported in some IDE's by use of a pre-parser.

In DarkEdit for example, go to Edit Options on the menu bar and click on the Editor Options tab. Put a tick into the Type extended syntax checkbox.

However, I've never been able to get it to work the way it's supposed to.

TDK_Man

Login to post a reply

Server time is: 2025-06-06 17:18:27
Your offset time is: 2025-06-06 17:18:27