Qbasicnews.com

Full Version: TYPES
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to learn abit more about QB.

ok, so you have stuff like types:

TYPE blablabla
xxx = 1
yyy = 2
CLOSE TYPE

DIM pp%(3) as blablabla

or sumthing like that.

what are types used for? what good are they?

OH and the last MAJOR Q. Ive always wondered what people use

playerx(2).element

things are used for?

What does the dot (.) mean? How could I use that in a game?
oh, crap. I just accidentally deleted what I was just typing.

ANyways, forget about types in QB.

"TYpes are good structured programming practices"
Load of BS.

Two disadvantages:

Arrays:
Code:
TYPE apple
color as integer
end type

apple.color(4) 'regular
apple(4).color 'TYPE
And no, it's not to differentiate between apple.color as INTEGER and apple AS TYPE.

If you try to do
DIM apple.size
you'll get an error, because apples have already been defined. Hence, you have to keep adding to the stupid type.

EDIT: So, the dot separates the type name from the type attribute in a type. But I always use it to make understandable variables.
TYPEs are good for working with games, because then you can create several different enemies or items or whatever, and still use the same variables with each of them.
Good thing: Imagine you re coding a RPG and you need to pass your hero's values to a bunch of functions. You simply do:

Code:
TYPE myPlayer
   strength AS INTEGER
   dexterity AS INTEGER
   fortune AS INTEGER
   defense AS INTEGER
   attack AS INTEGER
   numberoftoes AS INTEGER
   name AS STRING * 10
   colour AS STRING * 10
END TYPE

DIM player AS myPlayer

and you just call

Code:
displayValues player

instead of some kinda

Code:
displayValues strength, dexterity, fortune, defense, attack, numberoftoes, name, colour

Clarity and cleanness Tongue
Well, I wouldn't pass values.
thanks guys, that cleans things up alot!