Types

Blitz3D Forums/Blitz3D Beginners Area/Types

Jono(Posted 2003) [#1]
Hello, All

I've just ordered BlitzBasic, it's amazing piece of software just started getting my teeth into it. But i'm abit confused on how i go about using Types, i've never come across these before and was wondering if anyone has a basic example of how to use them. Maybe with comments even someone like me could understand. :)

Well, this is my first topic here, and i'm glasd to be part of the team, who said 2D gaming was dead. :D


soja(Posted 2003) [#2]
That's probably the most common question in the beginner's forum. Do a search in this forum, and I'm sure you'll see lots of information with examples, etc. You can also read articles on blitzcoder.

In a nutshell, types (more formally, Custom Types -- since integer, float, and string are all built-in types, but also types nonetheless) allow you to define your own variable type in Blitz. Each custom type has certain attributes, which can be made of other types.

You define a custom type like this, for example:
Type Player
    Field Name$
    Field Age%
End Type


Once you've defined the type, you can create variables for that type like this:
P1.Player

"P1" is the variable name, "Player" is the type, and since it's a custom type, it's designated with a ".".

Once you've defined the type and have a variable, you can create an instance of your type:
P1 = New Player


(You can also declare the variable and create a new type instance in one shot, like this)

P1.Player = New Player


Whenever you create a new type instance (with the New keyword), it automatically gets put into an internal linked list. There is one linked list for each kind of custom type. See "First" and "Last", etc.

You can change and access the attributes of P1 like this:
P1\Name = "Zaphod Beeblebrox"
P2\Age = 42


Well, I guess that's more than a nutshell. And actually, I only spoke a little bit on how to use types -- not much on why they're useful, etc. With this as a start, I recommend you read the forums, articles, online docs, etc. You'll pick it up in no time.


Andy(Posted 2003) [#3]
>I've just ordered BlitzBasic, it's amazing piece of
>software just started getting my teeth into it.
>
>Well, this is my first topic here, and i'm glasd to be
>part of the team, who said 2D gaming was dead. :D

Have you bought Blitz Basic or Blitz 3D?

Andy


Jono(Posted 2003) [#4]
I've just purchased Blitz Basic Plus, and thank you very much Soja, I will take a look at Blitzcoder. :D, A few articles written say that Type's are the hardest thing to learn when starting using Blitz Basic Plus. So I can't wait to I start understanding it, whenever that will be. lol :)


Shambler(Posted 2003) [#5]
Having used C++ for years I still have trouble getting my head around Blitz's type syntax >.<


Jono(Posted 2003) [#6]
I'm getting the hang of this slooowly, i was wondering is it possible for me to load up an image then to store this image in a Type pointer. Like:

Type Ships
Field Image
End Type

For A = 1 to 5
Blah\Image = LoadImage(Somethingwhatho!)
Next

I know it's not perfect coding just wanted to demostrate what i meant, to see if it was possible. :D


dynaman(Posted 2003) [#7]
Yes it is perfectly legal.


soja(Posted 2003) [#8]
Remember that Image is (in this case) the same as Image%.

In other words, LoadImage returns a pointer to be stored in Image, which is basically a 32-bit integer. It points to where Blitz stores the actual image data in memory.

This is how it's done for many types of data in Blitz.


(tu) sinu(Posted 2003) [#9]
types are awesome, in my opinion everyone should try to learn them.