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 / Type? As float? As byte?? oi

Author
Message
Indie Rock 13
20
Years of Service
User Offline
Joined: 1st Sep 2004
Location:
Posted: 22nd Oct 2004 19:27
Reading through the codebase and the forums I keep seeing people making declarations like "Type blah blah EndType". Is that an old command or a DBC command, cuz its not working with my DBP and I've never read anything about it anywhere.

And when people have 'x AS FLOAT' or 'y AS BYTE' what does that do, and whats the point? After reading about them, I'm not totally sure what a float is, or at least not why you would use a float for one thing but not for another. I'm trying to figure out some physics, but this was just a bit of a roadblock I figured would be easy to get help with.

Thanks!

Neeeeeeeewom!
RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 22nd Oct 2004 23:59 Edited at: 23rd Oct 2004 00:01
Types were not included in DBC only in DBPro so they should work, not sure why there not working for you, all I can suggest is check your code.

A type is basically a custom variable made up of other variables grouped together, think of it as a box partitioned into separate areas where different things can be stored based on what each area is defined as. First you have to define the type like :



Quote: "x as float"

- This creates a variable within the type which is set as a float (hence the 'as float'). The point behind it is, you have to tell DarkBasic what these different variables within your type will store. A float is used for holding numbers which contain a decimal point e.g. 56.784, whereas a string would be used for holding text like 'hello world' and an integer would be used for numbers which don’t contain a decimal point like '4576'.

Once this is done you then have to create an instance of your type in memory by defining a variable (a variable can be thought of as a box in which you can store some data) as your type, e.g.



You can then reference a section of your type like this:


- This will store the value 10.5 in the variable x within mytype.


The main reason you should be concerned about using different types of variables like float, string etc, is that most DBPro commands will only accept one type of variable, for example you couldn't pass a string to the position camera command without first converting it to a float, or integer. The real reason for different types of variables is to do with the way processors etc work; but you shouldn’t worry too much about that - and if you are interested there are plenty of web sites on the topic, just do a Google search.

Hmm, hopefully this didn’t turn out too confusing and makes some sense to you
Indie Rock 13
20
Years of Service
User Offline
Joined: 1st Sep 2004
Location:
Posted: 23rd Oct 2004 04:57
Thanks, everything I wondered about the code I found in the codebase makes sense now. I wish there a bit more documentation on the program to explain things like that, but I'm glad this forum is so helpful!

Neeeeeeeewom!

Login to post a reply

Server time is: 2024-09-23 03:31:13
Your offset time is: 2024-09-23 03:31:13