Created
December 3, 2015 11:31
-
-
Save csmith/9ed5994d84d52afceb24 to your computer and use it in GitHub Desktop.
Demo SpaceEngineers script showing use of ElapsedTime while accounting for various edge cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TimeSpan LastElapsedTime; | |
void Main(string argument) | |
{ | |
if (ElapsedTime.TotalSeconds == 0) | |
{ | |
// First run. The script has just been created/compiled, or the game was loaded. | |
SetupThings(); | |
} | |
else if (LastElapsedTime == null || ElapsedTime < LastElapsedTime.Add(TimeSpan.FromSeconds(10))) | |
{ | |
// ElapsedTime looks reasonable: either we have nothing to compare it to, or it's | |
// within 10 seconds of the previous value. | |
DoThings(); | |
LastElapsedTime = ElapsedTime; | |
} | |
else | |
{ | |
// ElapsedTime is weird. Maybe we've unpaused? | |
LastElapsedTime = ElapsedTime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment