Question About Dying

Ok, so I am making an RPG game of sorts and I have ran into only one problem.
I am using a void for the battling system and i wanted to know if anyone knew a way to "die" from that void.
Suggestions?
Change the function so that it returns a value, and use that value to indicate death or not.
Why not just give the character:

bool alive = 1;

And then if ever their health is below 1, alive = 0;
If you insist on keeping the function void, you can pass a reference into the function:

1
2
3
4
5
6
void Battle(bool &alive)
{
  ...
  alive = false;
  ...
}
Here is my take on it.

You have a battle and based on the battle different outcomes will happen such as, damage produce, health lost, etc.

the way I thought of it is that

you would have it set up like this (there is more then one way to do it so you don't have to follow me to the letter here);

type Health ( if any parameters) { Conditions, deals with death}
type damage( if any parameters) {Conditions}
type death (if any parameters) {Conditions.. something like revival)
Battle ( if any parameters) { conditions of battle, damage function is then used to deal with damage, you health will then be effected by the damage that is produced meaning that you will used the health function}
Last edited on
A general rule of thumb is to keep function IOs to a minimum.

A good way of dealing with this is to have a structure or class that represents the characters status (health, magic, experience, etc.) and pass that into the battle function. Then return the resulting character status struct at the end.

You could pass the struct by reference and modify it directly or you can pass the data and then return the result. It doesn't really matter which method you use.
Totally agree with stewbond I just didn't want to make it sound that it can only be those 2 because there is always a case where it can not be x_x.
Make a "bool" that holds a value of being dead or alive(0 or 1).

When you die, change the value to the appropriate death value(0 or 1).

That is all.

To add, a void function doesn't have anything to do with what can be done inside of it.
Last edited on
Topic archived. No new replies allowed.