Types (BP and B3D) (beginners)

Blitz3D Forums/Blitz3D Tutorials/Types (BP and B3D) (beginners)

eBusiness(Posted 2004) [#1]
First, what is a type?

A type is a collection of normal variables (integer, float and string), a type have a handle, you need this need this handle to acces the variables in a type. The smart thing about types is that you can easily make many types of the same kind.

How to create types?

Before you can create a type you need to setup the attributes of a type kind. It's done like this:
Type typename
Field variablename
Field othervariablename
Field stringvariablename$
Field floatvariablename#
End Type
In order to actually create a type you need to use the New command:
handlename.typename=New typename
Now 'handlename' contain the handle that you need in order to acces the newly created type. You can create multiple instances of a type with a For/Next loop:
For a=0 To 99
  handlename.typename=New typename
Next
It is important to note that: A handle can only contain one kind of type handles, and it does only contain one handle, so in the above example 'handlename' will only refer to the last created type. Also you need to assing a handle to a type when you create it, you can not just write 'New typename'.

How to use types?

The variables in a type can be used just like normal variables, in front of the variable name you need the type handle and a backslash ( "\" not "/" ), like this:
handlename\variablename = 2
a = handlename\variablename


Then how to acces the 100 types created in a previous example? I don't have all the handles.

You actually don't need all the handles, with a special loop you can acces all types of a kind:
For handlename.typename = All typename
  handlename\variablename = 2
Next
Here handlename will in turn adress to all the types of a kind.

Can I delete a type from memory?

Yes, and it's very simple:
Delete handlename
Note that only the instance that handlename currently refer to will get deleted.

Some usual misunderstandings:
"Types are needed for ... " No, types are not needed for the use of anything else in Blitz, they neither gives you any completely new options, they can be replaced by arrays and banks, but in many cases it is just easier to use types.

"EntityType is used to assign a type to an entity" Actually correct, the only problem is that it's not the type of type that this tutorial refer to, so leave it until you need collisions.

Some final words:
I have made this tutorial for beginners as many try to use them in a completely uncorrect way, I have left out some commands that are not needed to get started as these usually doesn't make as many problems (see Before, After, First, Last, Each and Insert in the docs for details on use), along with array/type combos.

I hope this will create a better understanding than the confusing entry in the docs.