You Like My Tutorials? Click The Banner To Keep 'Em Coming!

glGameDeveloper(): The Game Developer's Source for OpenGL Coding
Main Menu
Latest News
Archived News
Tutorials
Links
E-Mail Me

Other
Message Board
My Guestbook

Intro to Constants
 


Quick Intro to Constants Page 2 of 2
< Previous Jump to Page: 1 | 2 Next >

Quick Intro to Constants (con't)

Here's some examples of constants you might use in a game.

// gamestate constants
const int GS_NORMAL = 1;
const int GS_TITLESCREEN = 2;

// titlescreen constants
const int TS_MAIN = 0;
const int TS_LOAD = 1;
const int TS_SAVE = 2;
const int TS_OPTIONS = 3;
const int TS_EXIT = 98247;

This is just a quick example of constants for tracking the current game state. The numbers we set them to don't matter whatsoever. They can be anything, just as long as there isn't another similar constant with the same number. For example, your program doesn't have to care that TS_EXIT is ludicrously high. Just use TS_EXIT throughout your program and it always means TS_EXIT, no matter what number it's set to. Then when looking at your code you can obviously see what the constants are for, but you don't need to know the number it represents. Easy, huh?

Now if you have gamestate constants, you'll have to have a int GameState variable. In your game, you can set GameState = GS_NORMAL. Then later to check if the game state is normal, just say if (GameState == GS_NORMAL).

I hope this tutorial has been helpful. Let me know if you thought anything in it was confusing or made no sense. And if so I'll just laugh at you. =P

Quick Intro to Constants Page 2 of 2
< Previous Jump to Page: 1 | 2 Next >

This site best viewed with MS Internet Explorer 5.0 at 16-bit color and at least 800x600.

All Contents of this site are Copyright 1999, 2000 Joe Zimmerman. No part of this site (code, HTML, etc.) may be reproduced without my permission.

Click Here!