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.

AppGameKit Classic Chat / Using constants in include files

Author
Message
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 1st Jun 2012 14:18
.. works perfectly

and has done so for some time.

I know some people have had issues with this in the past.

With all the posts about what doesn't work in AppGameKit, I though it would make a nice change to report on what does.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Jun 2012 14:31
That does make a nice change thanks Marl! I didn't know that was fixed

Just as well or your compo entry wouldn't have worked would it? Or am I thinking of someone elses...?

Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 1st Jun 2012 14:47
No you're absolutely right - I used an entire include file for the constants.

Initially the constants were with the relevant sections of code, but were moved to their own file during the tidy up.

I don't mind sharing this as an example of how constants can help your code readability
basjak
14
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 1st Jun 2012 14:50
oh yes. thanks guys for telling me.

Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 1st Jun 2012 15:03
An important thing to remember is that constants are evaluated at compile time so the program does not have to do the maths when it runs.

Where DISPLAY_VMIN is the working resolution of the app (480.0) and VMIN_DIV_CELLS (8.0) is how many cells fit on the screen at zoom 1.0

would be compiled as
polomint
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location: Lancashire, United Kingdom
Posted: 1st Jun 2012 18:08
Yep, every project I start has a "constants.h" file, very useful.

Blackberry App Development & ZX Spectrum Game Development.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Jun 2012 18:17
I think the issue was a constants file in Tier1.

It appears to work fine in Tier1, as long as you include it in the main.agc file relatively early.

Cheers,
Ancient Lady
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 1st Jun 2012 19:21
Is it possible to use TRUE and FALSE as constants?

I don't get an explicit "reserved word" error, but they don't seem to be working as constants, either.

Puzzling.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Jun 2012 19:44
Rich, I'm betting the answer is 'no'.

The compiler would encounter the words 'TRUE' and 'FALSE' and probably assume undeclared, unassigned variables and default both to zero.

But, I could be wrong.

Cheers,
Ancient Lady
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 1st Jun 2012 20:27 Edited at: 1st Jun 2012 20:33
If they don't, you could use IS_TRUE and IS_FALSE, which also read really well in code.

Edit: Just Checked and TRUE and FALSE do work as constants.

I would still be wary using them though, it could cause issues in future releases if they get adopted as reserved words
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Jun 2012 20:39
I misunderstood. I thought Rich meant use TRUE and FALSE as the assigned value to some other constant. Doh!

Cheers,
Ancient Lady
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 1st Jun 2012 21:52
I like IS_TRUE and IS_FALSE, thanks Marl, good idea!

Login to post a reply

Server time is: 2024-05-08 14:06:55
Your offset time is: 2024-05-08 14:06:55