A good, simple, and powerful idea that is worth taking time to really think about.
My second-hand knowledge of enum and constants is actually pretty good, especially for the way they work in game.
A good idea. But how do we implement them in game? Let’s imagine we have a game where you have to choose between two options. You have to build a spaceship and a house. You pick one.
That simple. But it’s hard to remember it because we use constants for everything, and everything is constantly changing. There’s a constant price to pay for the spaceship, a constant amount of time it takes to build the house, but there’s also a constant amount of energy consumed.
The constant is the amount of time that you have to spend doing something. And that’s about it. But its hard to remember that constant. Because if you’re trying to build a house and you don’t want to spend a lot of time building the house, or you want to build the spaceship and a house, you can use constants. But its hard to remember that constant.
A constant is the amount of time that you have to spend doing something. And that’s important. If youre trying to build a house, you’ve probably got a constant of somewhere in the thousands of dollars.
So let’s go ahead and create something that lets us do some fun stuff with it. We should then spend a little bit of time and spend more time building something. Let’s do that.
This is a great example of an intial design that ends up suffering from an overuse of a bit of code. The thing is that a constant is not a variable. It is a variable that is assigned a value in the first place, and only then can you use it. So we should probably remove one of the constants and just create a constant that takes care of the rest.
That being said, constants should be used sparingly. They should be as short as possible. They should be used for the most trivial purpose. They should be used in very simple ways that don’t require special treatment. They should be used very rarely.
It is true that you cannot create a constant with a value without assigning it to a variable first. But what you should do instead is return an integer from your function and assign that integer to a variable. For example, I could return the integer 5, assign that variable to a constant called “5”, and then return the integer 5. Or I could return the integer 5 and assign that to a constant called “5”, and then use that as the return value for my function.