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 / I don't know how to word this as a subject...

Author
Message
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 9th May 2005 15:54
Sorry, I could think of how to subject this question, but I've been figuring out some things here on my own but now I'm stuck. Taking a look at the ball physics code by Walaber from the codebase, I noticed somethings that confused me. On one line he had this
Right now I'm refering to Ball as Object. Now I've noticed shortly after that he has this
Now after Ball he has a period which then says Pos for position, Vel for velocity and status. I just happen to notice he used periods between each word rather than making it one whole word or using underscores. Now let's take Ball.Pos.x for an example. Ball I'm assuming is his object that he defined when he typed Ball as Object, then I noticed for Pos he had this defined somewhere else above it
then before that he defined the x and y like this
No forgive me for throwing this all in here and not making sense, but it didn't take me long to figure out by myself that these all tie in to each other somehow, but I just can't quite figure out how. Can someone possibly explain this to me if I made enough sense. I'm not looking at how it makes this particular program work, but just so how I can see for future reference how I can use this myself.
NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 9th May 2005 16:32
Clickable SMiley,

Do you code in DarkBasic Classic or DarkBasic Professional?


+NanoBrain+
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 9th May 2005 16:34
Ooops, I'm sorry, forgot to mention Professional. I'm assuming this all new stuff to Pro not available in classic? If so that's prolly why I'm lost on this.
NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 9th May 2005 16:40
Clickable SMiley,

Yes, the periods in between pos, vel, y, etc, is part of the syntax of the DarkBasic Professional language. Some are types of Boolean variables and some are for other uses.


+NanoBrain+
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 9th May 2005 16:44
Hmmm, sounds like it might be a little bit ahead of my level of knowledge. Just thought to ask as I was curious to this way of coding. Never seen anyone take that aproach.
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 14th May 2005 06:31
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 caseu 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...

Login to post a reply

Server time is: 2024-09-23 19:28:53
Your offset time is: 2024-09-23 19:28:53