Why can't C++ add, subtract, divide, or multiply?

I'm currently learning how to use the Unreal Engine and want to learn C++. To better understand the language, I tried to make a console game with it, but there are a few errors in the game and I don't understand why they exist.

Leg of a gold mine In the game you are supposed to get 75G and in the first round the player's power is supposed to increase by 50, but it always says (no matter how often I buy the mine) that I have 75G and player power is 50 and when I want to buy a tower it says I don't have enough G even though the tower costs 50G.

Can anyone help me?

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
6 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
unsignedInt
2 years ago
  1. You should upload a minimal code example that highlights the problem – or at least highlight the interesting lines in your code. Otherwise, it’ll take too long to track the code.
  2. In every game-tick you’ll start GameVoids::MainGame() a new instance of Vars, which is then changed. This isn’t the same instance as in your main function. These are two completely different objects; the changes are not transferred to v in the main(). I would either set the whole code (i.e. the game loop) in MainGame() and just let all game logics run there (i.e. main() only calls GameLoop(), but otherwise does nothing). Or simply transfer the instance of Vars by reference to the function and use it there instead of using a new, different object each time.
  3. Apart from that, you should think again about how you store and process the game state and how you use it in OOP classes.
unsignedInt
2 years ago
Reply to  BossWither

Yes, my second point fully answers your question. You create an object a and an object b, then change b and wonder why a was not changed. You should either send the target object into the changing functions as a pointer/reference or consider a different, more meaningful program structure that simplifies you all. As I said, I would rather move all logic into class, image the gamestate through the class and make the functions non-static (i.e., use OOP as it is actually intended).

W00dp3ckr
2 years ago
Reply to  BossWither

The criticism is quite fundamental. He says: clean up and solve your problems.