Jump to content
  • Advertisement
Sign in to follow this  
LAURENT*

My code will not work when it is watched

This topic is 1003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My code will not work when watched. I programmed my character to auto regenerate it's health but it only seem to regenerate when I pull up another window over my game's window. Does anyone have some kind of idea why this happens?

 

The scenario is this in a nutshell.

 

1)Start Game

2)Jump

3)Minus health with every jump

4)Waits for health to regenerate.

5)Nothing.

6) Clicks on another window

7) returns to game window

8)character regenerate health.

 

I thought I was being impatience but I ran several test, this code is acting funny.

Share this post


Link to post
Share on other sites
Advertisement

Sounds like it is regenerating, but the screen isn't redrawing like it's supposed to.

 

When the window gets covered, it invalidates the region, and when the window is uncovered again, it forces a repaint which happens to show the health now full.

 

Debug the program using a debugger and see for sure.

Share this post


Link to post
Share on other sites

Sounds like it is regenerating, but the screen isn't redrawing like it's supposed to.

 

When the window gets covered, it invalidates the region, and when the window is uncovered again, it forces a repaint which happens to show the health now full.

 

Debug the program using a debugger and see for sure.

Doesn't seem like that the problem. I put a break point in a spot that should alert me if values were changing. Does a break point count as debugging?

Share this post


Link to post
Share on other sites


Doesn't seem like that the problem. I put a break point in a spot that should alert me if values were changing. Does a break point count as debugging?

 

Well.... does the breakpoint hit when you switch to another window? If so, what leads to that code being called? What does the callstack look like? Then try to figure out why that code wouldn't get called when you don't switch windows.

Share this post


Link to post
Share on other sites

 


Doesn't seem like that the problem. I put a break point in a spot that should alert me if values were changing. Does a break point count as debugging?

 

Well.... does the breakpoint hit when you switch to another window? If so, what leads to that code being called? What does the callstack look like? Then try to figure out why that code wouldn't get called when you don't switch windows.

 

Yes it does, only when I click on another window does the break point activate. I will post up the function.

Share this post


Link to post
Share on other sites

[

void  Character::Character_Stats_Controller(Uint32 deltaTicks)
{
	if(Game_Mode == GAMEPLAY_MODE)
	{
		/////////////////////////////////
		// HEALTH REGENERATION.
		/////////////////////////////////
		Character_Health_Timer += 20 * ( deltaTicks / 1000.f ); 
		if (Character_Health < 20)
		{
			

			if (Character_Regeneration == false)
			{
				// Set wait time
				Character_Health_Time = rand()% 3 + 1;
				// Set health recovery
				Health_Plus = rand() % 3 + 1;
				//Ready to regenerate
				Character_Regeneration = true;
				//Start at zero
				Character_Health_Timer = 0;
			
			}
			
			// If the timer passes the wait time
			if (Character_Health_Timer >= Character_Health_Time)
			{
				//Give the character health
 				Character_Health += Health_Plus;
				//Set the health to false to be ready to recover again. 
   				Character_Regeneration = false; 			
			}
		}
		//Max health, magic number. 
		if (Character_Health > 20)
		{
			Character_Health = 20;
		}
	}
}

This is my code.

Share this post


Link to post
Share on other sites

(New member here, I'll try to be as helpful as possible.)

 

Like Servant previously stated, it sounds like there is a problem with how the program is redrawing. Can you show us how you render/update your character class?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!