View Single Post
  #104  
Old 05-14-2011, 09:16 PM
TheEnlightenedFlorist TheEnlightenedFlorist is offline
Approved Member
 
Join Date: May 2011
Location: SLC, Utah, USA
Posts: 143
Default

Thanks for the thread Ataros. Very helpful.

Is there a reason you guys are using "ticks" to measure time. C# has a few different ways of keeping track of time. Here's an example using the Stopwatch class. Don't get me wrong, modulus is great but this stopwatch is probably more accurate and it's a heck of a lot more readable.

Code:
using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;
using System.Diagnostics;   //contains Stopwatch class

public class Mission : AMission
{
    int timesRun = 0;   //count how many times sub-mission has been run

    Stopwatch timer = new Stopwatch();   //timer. Counts... time...

    public override void OnTickGame()
    {
        
        //if sub-mission has never been run, run it
        if (timesRun == 0) 
        {
            //start timer
            timer.Start();

            GamePlay.gpPostMissionLoad("missions/Multi/MyMissions/mission1.mis");
            timesRun++;

            // prints message on screen after mission load
            GamePlay.gpHUDLogCenter("Hello, world! Mission1.mis loaded!");
        }

        //if five or more minutes have elapsed since the timer was started, run sub-mission
        if (timer.Elapsed.Minutes >= 5)
        {
            GamePlay.gpPostMissionLoad("missions/Multi/MyMissions/mission1.mis");
            timesRun++;

            GamePlay.gpHUDLogCenter("Hello, world! Mission1.mis loaded!");

            //reset timer to zero and restart it
            timer.Restart();
        }
    }
}
Reply With Quote