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.

Newcomers DBPro Corner / noob TYPE question

Author
Message
Tobo
19
Years of Service
User Offline
Joined: 12th May 2005
Location:
Posted: 18th May 2005 15:43
I'm currently trying to get my head around this TYPE stuff.

But my DBPro doesn't accept it as a command! It doesn't turn blue, and I can find no help files associated with TYPE !

I have DBPro 1.058.

Should this command actually exist, can you loop through types?
jlb1987
19
Years of Service
User Offline
Joined: 10th May 2005
Location:
Posted: 18th May 2005 18:53
I just did a quick search for you (I don't know about this 'type' command myself) but if it is type arrays you are looking for there is a post on that saying there is a tutorial on this website. Somewhere. Good luck in finding it.

"We dads have a saying- You can't fix it 'til you've broken it." Brian Johnson.
Anti Dragon
20
Years of Service
User Offline
Joined: 19th Feb 2004
Location: Lost....If found, please return.
Posted: 18th May 2005 19:44
You use type to generate custom variables. For example, say you have an enemy in your game that has an object (obviously), health and attack values. Instead of using multiple variables or arrays to keep track of these values, you can parcel them up into an enemy Type:



You don't have to use the "AS x" when defining your fields (the components that make up your type) but it helps to ensure you don't apply incoorect values to them later on. Also, you can have arrays of types - so you could have an array of Enemy types to keep track of all the enemies in your game.

....So I lurked for a year, deciding when to strike....
jlb1987
19
Years of Service
User Offline
Joined: 10th May 2005
Location:
Posted: 18th May 2005 21:23
That is an unusually useful (minor) feature. Can't say I ever heard of it until now.

"We dads have a saying- You can't fix it 'til you've broken it." Brian Johnson.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th May 2005 21:34
Last month's tutorial. I would recommend downloading the source code, it amkes the whole thing easier to understand when you see it in action:

http://www.thegamecreators.com/data/newsletter/newsletter_issue_28.html#9

BatVink
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 19th May 2005 08:52
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


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



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



This way you only have use one variable name to call each Object.


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


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



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



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...
master programmer
19
Years of Service
User Offline
Joined: 30th May 2005
Location: 3D Space
Posted: 31st May 2005 15:44
I don't think "type" is a command...is it?


______________________________________
<<<<I can program using anything>>>>

Login to post a reply

Server time is: 2024-11-12 01:43:15
Your offset time is: 2024-11-12 01:43:15