Globals as default input for a method.
BlitzMax Forums/BlitzMax Beginners Area/Globals as default input for a method.
| ||
Actually, never mind. It was a stupid question. Now I am left with the question of, why doesn't the compiler consider this to be a valid constant? Const GRAPHICS_WIDTH = 320*Sqr(2) Thanks again for any help. |
| ||
You should get an error saying... Function defaults must be a constant because they're set at compile time and not runtime. |
| ||
Because it doesn't know what the return from sqr(2) is going to be at compile time. |
| ||
No, you cannot do that. You can use a Const as a default input, but not a Global. Like this:Const test = 1 Type t Method a(b = test) Print b EndMethod End Type Another alternative is to use a redundant default parameter (ie. one which you know is incorrect), and then replace it with a global. This isn't exactly nice, but it works: Global test = 1 Type t Method a(b = -9999) If b = -9999 Then b = test Print b EndMethod End Type[edit] DOH! |
| ||
Thanks everyone for your help. The fact that people replied to my post before I even edited it says a lot about this community. The speed of the responses is staggering. For the moment I have just inputted sqr(2) numerically into the constant. Is there a better way? |
| ||
What do you want to use it for? |
| ||
There are a whole bunch of graphics functions that need to know the graphics width and graphics height. Their pretty much the only two constants that use sqr(2) in the "game" though. |
| ||
I don't think I understand. Why can't they use the standard graphicswidth() and graphicsheight() functions? |
| ||
The Graphics Width and Height constants that I'm using are used to set the windows dimensions. However, they are also used for a lot of graphics functions that may occur before the window is created. I mean, the method works, it's just slightly cumbersome. |
| ||
I think the question still remains why 320*sqr(2)? Unless Im missing something realy obvious |