Click here to Skip to main content
15,885,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
c#</pre>
if (bool232 == true)
            {
                if (gameTime.TotalGameTime.TotalSeconds >= 3)
                {
                    this.Exit();
                }
            }
            else
            {
            }


For some reason this code is making my game exit immediately when the boolean becomes true instead of waiting 3 seconds
any idea why?
Posted
Updated 10-Dec-13 10:18am
v2

Ok, you edited the question to make it ever so slightly different, but here is what is going on...

C#
if (bool232 == true)


When that is true, it will start executing inside the if... next is

C#
if (gameTime.TotalGameTime.TotalSeconds >= 3)


Here, if the TotalGameTime is over 3 seconds, it will execute the next line, which exits your game. This line is not a delay, it just check to see if you have been playing for more than 3 seconds. If you want to delay, you have to so some kind of sleep, like:

C#
System.Threading.Thread.Sleep(3000);
this.Exit();
 
Share this answer
 
Well obviously the .TotalSeconds is greater than or equal to 3 at that point.

My first check would be to see if TotalSeconds is returning milliseconds a 1000 milliseconds is much greater than 3. Or is the TotalSeconds being initialized correctly?
 
Share this answer
 
Comments
Ron Beyer 10-Dec-13 16:30pm    
Why would TotalSeconds return milliseconds? You may want to look at the XNA API to see what it returns, its not a variable that he controls, its simply a game referenced timespan.
bowlturner 10-Dec-13 17:17pm    
Well true, I don't know who wrote the code nor what they are returning, the assumption of course is the number of seconds since the game started. But that is an assumption. I of course thought he knew that for it not to close the game it would have to be less than the first 3 seconds. I guess I wasn't thinking simple enough.
Please don't repost:

why doesnt this code work?[^]
 
Share this answer
 
Comments
Member 10442210 10-Dec-13 16:16pm    
sorry but I didnt repost, thats a different question regarding the same code
Ron Beyer 10-Dec-13 16:17pm    
Its exactly the same question, read the answers to the other one and you will fix it.
Member 10442210 10-Dec-13 16:22pm    
In that question I asked why my code was exiting after 3 seconds
here I asked why my game is exiting when the boolean becomes true

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900