Update function wont trigger

Using latest version of visual studio as of 9/02/18 on windows 10

Hey guys so basically im wondering why my update function doesn't work and keep updating. Thanks :)

Here's the pastebin for the code: https://pastebin.com/8fgdjaUj

It triggers when first run but as soon as i go to mainroom it stops. In the training segment i've made it so my health increases if i run then my health will display in the main room.
A user can enter their name, then hit return and get a list of options. They can check their health, decrease the enemy's health, battle, etc.. The problem is that when the update method is called and we enter the Mainroom, you have recursive calls to Mainroom, and the other calls. You are stuck up on the stack, and have not unwound from it. It's just recursion is limiting you to one call of v[i]->update().

If we play the game too much, we will run out of random access memory by putting too much on the stack.

You might want to take the code that's in the function Mainroom, and put it down above your v[i]->update() method so it's no longer recursive. And you don't really need the for loop wrapping your while(true). Then your Battle function would just return.

You only need one main loop in the program, and simply have the Mainroom method be a chooser of where to go but return the option and THEN choose which room. So structure things such that they always return from their battle, health-check, etc..

I view the Main room as being a place just to decide where to go next. Am I wrong?

Sorry, I normally only use recursion when I'm searching finite-sized graphs and trees. It can get out of hand although I realize you have some counters in there to break up the recursion. You may want to put a break in your code (if you still want the recursion). You need a static int declared outside the functions that keeps track of recursion if you want a recursive program.

Might be easier to just structure it as below:

while (true)
{
response = Mainroom(); // Display health, etc.., get their response, and
// return (ie. exit the Mainroom).
switch(response)
{
case Battle;
case Health-check;
}

};

Hitting F5, then opening the call stack under Windows->CallStack reveals the recursion (although there are sequences of keystrokes one can type that might cause a break, I have to test this).

Here's a run that tests the loop some:

Update number 0
Update number 0
Hello, What is your Name?
Fred
That's an interesting name Fred

How Much Money Do I Have(1)
How Much Health Do I Have(2)
I Want To Quit(3)
Room Select(4)
Health 100
XP 0
4
What Room Do You Want To Go To?
Training(1) Battle(2) Main(3)
2
Under Renovation
How Much Money Do I Have(1)
How Much Health Do I Have(2)
I Want To Quit(3)
Room Select(4)
Health 100
XP 0
1
0
How Much Money Do I Have(1)
How Much Health Do I Have(2)
I Want To Quit(3)
Room Select(4)
Health 100
XP 0
1
0
How Much Money Do I Have(1)
How Much Health Do I Have(2)
I Want To Quit(3)
Room Select(4)
Health 100
XP 0
4
What Room Do You Want To Go To?
Training(1) Battle(2) Main(3)
1
What Do You Wish To Do? Enemies Health 100
Attack(1) Run(2)
1
What Do You Wish To Do? Enemies Health 98
Attack(1) Run(2)
1
What Do You Wish To Do? Enemies Health 96
Attack(1) Run(2)
2
How Much Money Do I Have(1)
How Much Health Do I Have(2)
I Want To Quit(3)
Room Select(4)
Health 201
XP 0
4
What Room Do You Want To Go To?
Training(1) Battle(2) Main(3)
3



> Room.exe!MainRoom() Line 110 C++
Room.exe!roomSelect() Line 178 C++
Room.exe!MainRoom() Line 148 C++
Room.exe!Training() Line 86 C++
Room.exe!Hit() Line 61 C++
Room.exe!Training() Line 79 C++
Room.exe!Hit() Line 61 C++
Room.exe!Training() Line 79 C++
Room.exe!roomSelect() Line 168 C++
Room.exe!MainRoom() Line 148 C++
Room.exe!MainRoom() Line 134 C++
Room.exe!MainRoom() Line 134 C++
Room.exe!Battle() Line 101 C++
Room.exe!roomSelect() Line 173 C++
Room.exe!MainRoom() Line 148 C++
Room.exe!Updates::update() Line 203 C++
Room.exe!main() Line 246 C++
[External Code]
Last edited on
Topic archived. No new replies allowed.