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 / #constant?

Author
Message
RadiusOFT
19
Years of Service
User Offline
Joined: 14th Jul 2005
Location: Aloha, OR(egon)
Posted: 30th Aug 2006 07:30
what is a #constant?

Do or do not... there is no try -yoda
cats fit best in a george forman - not yoda
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 30th Aug 2006 09:36 Edited at: 30th Aug 2006 09:36
A #Constant is the opposite of a variable.
Like a variable it too can hold a value but unlike a variable it's value is constant.
Sounds pretty pointless right?

Well, not really. I find they come in very handy when writing your code because they tidy things up a little.
For example: If I have a complex equation that I struggle to remember and can't be bothered typing each time I use it, then I could declare it as a #constant (have a look at 'c' in the code) or maybe I just want to replace values with words to make it make it easier to remember what they are doing. (Black & White in the code)




RadiusOFT
19
Years of Service
User Offline
Joined: 14th Jul 2005
Location: Aloha, OR(egon)
Posted: 30th Aug 2006 21:17
ty

Do or do not... there is no try -yoda
cats fit best in a george forman - not yoda
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 7th Sep 2006 06:14
Also, MACROS help, but I don't know if DBPro has them. The constants come in handy for values like pi and 2pi, and also tolerances in math, too.

Scraggle, I like your code...especially your formatting! Very clean and readable. (Yeah, I see the extra tab in line #1, but really...!)
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 7th Sep 2006 10:15
DBPro has Functions, which work a lot like marcos (same principle for the most part - though some may argue that).

Constant simply does a Find-and-Replace through the code when it is being compiled. Try Scraggle's code using the Step Debug mode and take a look at what the constants look like. Knowing this, you can use #Constant to it's full advantage. For example, you could write a function and have it called by using a constant, so it would work just like your very own DBPro command.

Here's a popular function that I've added a #Constant to in order to make it more command-like.




Open MMORPG: It's your game!
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 11th Sep 2006 05:57
Yeah, RiiDii...I have seen that code, and I can't get past the name. (That is from C programming, however.) That is a nice explanation of it, BTW. Now, I assume that it is in its own source file, and #included in your projects, or do you cut and paste?
RadiusOFT
19
Years of Service
User Offline
Joined: 14th Jul 2005
Location: Aloha, OR(egon)
Posted: 17th Sep 2006 04:19
this brings me to my next question, what is a float?

Do or do not... there is no try -yoda
cats fit best in a george forman - not yoda
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 17th Sep 2006 05:20
Floats are real numbers, as opposed to whole numbers. They have a decimal point. They are 4 bytes wide. It is necessary to use floats in 3D because of the math involved. Even simple math like 3 / 2 will not work properly with integers, for example. With floats, you can preserve the accuracy of math operations better.
RadiusOFT
19
Years of Service
User Offline
Joined: 14th Jul 2005
Location: Aloha, OR(egon)
Posted: 17th Sep 2006 07:48
thanks

Do or do not... there is no try -yoda
cats fit best in a george forman - not yoda
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 18th Sep 2006 01:54
No, thank you...I'll try that tonight with my grill.

Login to post a reply

Server time is: 2024-11-26 12:47:47
Your offset time is: 2024-11-26 12:47:47