Like BatVink said, if you look at the last newsletter, it has a tutorial on assets, that will explain what you are looking at better. BTW an asset is a user defined type.
You can create variables such as
ObjectX#
ObjectY#
ObjectZ#
But these can only hold one number each, so if you were to want to control more than one object you would have to create variables as this
Object1X#
Object1Y#
Object1Z#
Object2X#
Object2Y#
Object2Z#
After a while you will loose track of each object, the above can get very confusing.
On top of this, if you wanted to update each objectY# according to lets say the matrix ground height, using the above technique can cause very long code (which i wont go into incase you are not this advanced yet, I dont want to totally confuse you)
A better way would be create an array, such as
rem This will create the variable ObjectX which you can store up to 10 different numbers
rem The reason you can store 10 numbers yet I have only stated 9 is because you use ObjectX#(0) as the first number.
dim ObjectX#(9)
This way you only have use one variable name to call each Object.
ObjectX#(0) = 0
ObjectX#(1) = 200
Position object 1,ObjectX#(0),0,0
Position object 2,ObjectX#(1),0,0
The above will position object one at coordinates 0,0,0. Object Two will be at the coordinates 200,0,0
I wont go into arrays in any more depth now as you are confused about types.
Please note that after each variable I have used the # symbol, this tells DB that it is real number (it can contain decimals). Another name for a real number is a float.
If you were not to include this, it would become an integer where as if you were to use the symbol $ at the end, the varible would become a string, this is a set of characters i.e
Name$ = "name here"
Arrays are good, but what happens if you wanted to create for example a character in your game called Hero and you wanted to know Hero's X Y and Z position as well as his X Y and Z angle + his nicname.
You could use the following code
rem Object Position
dim ObjectPX#(9)
dim ObjectPY#(9)
dim ObjectPZ#(9)
rem Object Angle
dim ObjectAX#(9)
dim ObjectAY#(9)
dim ObjectAZ#(9)
rem Age
dim ObjectNicname$(9)
ObjectPX#(1) = 500
ObjectNicname$(1) = "Jimmy"
This code will work, and if you are unhappy about using Types, then use the above code, with arrays for your game. However a more structured game would benifit from the below
TYPE object
pX as float
pY as float
pZ as float
aX as float
aY as float
aZ as float
ENDTYPE
Hero as object
Hero.pX = 200
In Types you can no longer use the # or $ symbol, in order to create a float or a string you must tell DB that you want pX to be a float.
Then I have told DB that I want the variable Hero to inherite, or store all of the USER DEFINED TYPE object variables.
You can even tell a USER DEFINED TYPE to inherite another USER DEFINED TYPE
Such code would like this
TYPE details
Nicname as string
ENDTYPE
TYPE object
pX as float
pY as float
pZ as float
aX as float
aY as float
aZ as float
Info as details
ENDTYPE
Hero as object
Hero.Info.Nicname = "Jimmy"
Now why have I put
Hero.Info
When clearly I have said Info is a details, shouldnt it be
Hero.details
NO! Is the short answer. Just like when I have said pX is a float, I write pX = 0, not float = 0.
The same is for types, Info as details, hence the
Hero.Info.Nicname = "Jimmy"
If you understand arrays, try experimenting with
dim Hero(9) as object
One last word of advise, at the moment you cannot create an array inside of a User Defined Type (UDT) but you can create a Type of an array. So the following works
Where as this wont
Hope this helps!!
James Morgan
My first sexual experiance was in my girlfriends house, then she came down stairs and ruined it...