Results 1 to 21 of 21

Thread: Timer and message display

  1. #1
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Timer and message display

    Hi folks, me again

    OK so working on having a list of messages displayed at timed intervals one after the other. Downloaded ATAG_Oskar's code for the mileage mission from here https://theairtacticalassaultgroup.c...downloadid=195 and added in [using System.Diagnostics;] at the top of the file

    Here is my code:

    Code:
    public class Mission : AMission
    {
        //Declare stuff that is going to be used in the class
        Stopwatch MissionTimer = new Stopwatch(); //Create new timer
        int intArrayMsg = 0; //This holds the current message number that will be displayed
        List<string> listStrMsg = new List<string>(); //List that will hold all the messages
    
        public override void OnBattleStarted()
        {
            base.OnBattleStarted();
            //Add each message to the list -------------------------
            //Looks like a 100 characters is OK to display on screen i.e.
            listStrMsg.Add("Good morning pilot, today you are going to have a lesson on starting and taking off in the Hurricane.");
            listStrMsg.Add("This is the second message...");
            listStrMsg.Add("And this is the third...");
    
            MissionTimer.Start(); // start the stopwatch
        }
    
        public override void OnTickGame()
        {
            base.OnTickGame();
    
            //GamePlay.gpHUDLogCenter(listStrMsg[intArrayMsg]); //Display the first message
            DisplayMsgToPlayer(intArrayMsg);
    
            if (MissionTimer.Elapsed.TotalSeconds >= 6) // after 6 seconds
            {
                DisplayMsgToPlayer(intArrayMsg); //Should be message 2
            }
    
            if (MissionTimer.Elapsed.TotalSeconds >= 10) // after 10 seconds
            {
                DisplayMsgToPlayer(intArrayMsg); //Should be message 3
            }
        }
    
        public void DisplayMsgToPlayer(int intMsgToDisplay)
        {
            GamePlay.gpHUDLogCenter(listStrMsg[intMsgToDisplay]);
    		intArrayMsg++;
        }
    }
    Problem I have is that it immediately displays the last message (i.e. the 3rd) in the list, can anyone tell me where I am going wrong please?

    Cheers
    Glyn

  2. Likes ATAG_Snapper liked this post
  3. #2
    ATAG_Colander's Avatar
    Join Date
    Nov 2011
    Location
    Bir Tawil
    Posts
    11,128
    Post Thanks / Like
    Total Downloaded
    255.73 MB

    Re: Timer and message display

    Quote Originally Posted by GlynD View Post
    if (MissionTimer.Elapsed.TotalSeconds >= 6) // after 6 seconds
    Total seconds will be >6 after 6 seconds and will remain >6 at 7, 8, 9, 10, etc...
    So, you could fix it with something like this:

    Code:
    if (MissionTimer.Elapsed.TotalSeconds >= 6 && intArrayMsg == 1)
    This will skip this "if" once you are past message 2

  4. Likes Baffin liked this post
  5. #3
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Re: Timer and message display

    Thanks ATAG_Colander, will give this a go tomorrow - got square eyes now from staring at code

    Cheers for the quick reply
    Glyn

  6. #4
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Re: Timer and message display

    Arghhh - still jumping to displaying the last message in the list! Here is my modified code (which compiles fine in the FMB):

    Code:
    public class Mission : AMission
    {
        //Declare stuff that is going to be used in the class
        Stopwatch MissionTimer = new Stopwatch();
        int intArrayMsg = 0; //This holds the current message number that will be displayed
        static List<string> listStrMsg = new List<string>(); //List that will hold all the messages
    
        public override void OnBattleStarted()
        {
            base.OnBattleStarted();
            MissionTimer.Start(); // start the stopwatch
            BuildStringList(); //Run the list builder
            //MissionTimer.Restart(); // stopwatch reset to 0 and restart
        }
    
        public override void OnTickGame()
        {
            base.OnTickGame();
    
            //GamePlay.gpHUDLogCenter(listStrMsg[intArrayMsg]); //Display the first message
            DisplayMsgToPlayer(intArrayMsg); //Should be message 1 (List item 0)
            
            if (MissionTimer.Elapsed.Seconds >= 6 && intArrayMsg == 1) // after 6 seconds
            {
                DisplayMsgToPlayer(intArrayMsg); //Should be message 2 (List item 1)
            }
    
            if (MissionTimer.Elapsed.Seconds >= 10 && intArrayMsg == 2) // 5 seconds
            {
                DisplayMsgToPlayer(intArrayMsg); //Should be message 3 (List item 2)
            }
        }
    
        public void DisplayMsgToPlayer(int intMsgToDisplay)
        {
            GamePlay.gpHUDLogCenter("Msg ID:" + intMsgToDisplay + " " + listStrMsg[intMsgToDisplay]);
    		intArrayMsg++;
        }
    
        static void BuildStringList() //Add each message to the list
        {
            //Looks like a 100 characters is OK to display on screen i.e.
            listStrMsg.Add("Good morning pilot, today you are going to have a lesson on starting and taking off in the Hurricane.");
            listStrMsg.Add("This is the second message...");
            listStrMsg.Add("And this is the third...");
        }
    }
    Thanks for any insights in advance. Done some VBA coding before however C# is new to me, so I am still hunting about on the interwebs for example of how to do stuff
    Glyn

  7. #5
    ATAG_Colander's Avatar
    Join Date
    Nov 2011
    Location
    Bir Tawil
    Posts
    11,128
    Post Thanks / Like
    Total Downloaded
    255.73 MB

    Re: Timer and message display

    Try this (have not tested it):
    Code:
        public override void OnTickGame()
        {
            base.OnTickGame();
    
    	int MessageToDisplay=-1;
    		
            
    	// Choose which (if any) message to display...
            if (intArrayMsg == 0 && MissionTimer.Elapsed.Seconds >= 0) // after 6 seconds
                MessageToDisplay=intArrayMsg;
    		
            if (intArrayMsg == 1 && MissionTimer.Elapsed.Seconds >= 6) // after 6 seconds
                MessageToDisplay=intArrayMsg;
    
            if (intArrayMsg == 2 && MissionTimer.Elapsed.Seconds >= 10) // 5 seconds
                MessageToDisplay=intArrayMsg;
    
    		
    		
    	// If a message should be displayed, then do it. Else do nothing.
    	if(MessageToDisplay>-1)
    		DisplayMsgToPlayer(MessageToDisplay); //Should be message 1 (List item 0)
        }
    Note that there are better/cleaner ways to do this but let's keep it simple for now
    Last edited by ATAG_Colander; Jan-31-2022 at 09:38.

  8. Likes GlynD liked this post
  9. #6
    Supporting Member
    Join Date
    Oct 2020
    Posts
    198
    Post Thanks / Like
    Total Downloaded
    197.43 MB

    Re: Timer and message display

    You call the function DisplayMsgToUser each time the timer ticks and then intArrayMsg is incremented at each tick.
    Did you look at the console ? It will be error messages in it like "index out of range" or something like that.

    Try this :

    Code:
        public override void OnTickGame()
        {
            base.OnTickGame();
    
            //GamePlay.gpHUDLogCenter(listStrMsg[intArrayMsg]); //Display the first message
            if(intArrayMsg < 3)  // all messages not displayed yet  
            {
               if(intArrayMsg == 0) DisplayMsgToPlayer(intArrayMsg); //Should be message 1 (List item 0)
            
               if (MissionTimer.Elapsed.Seconds >= 6 && intArrayMsg == 1) // after 6 seconds
               {
                   DisplayMsgToPlayer(intArrayMsg); //Should be message 2 (List item 1)
               }
    
               if (MissionTimer.Elapsed.Seconds >= 10 && intArrayMsg == 2) // 5 seconds
               {
                   DisplayMsgToPlayer(intArrayMsg); //Should be message 3 (List item 2)
               }
            }
        }
    "You can teach monkeys to fly better than that!"

    Win 11 Pro - I5-12600KF - 32GB Ram - RTX 3080 TI 12GB (non OC) - SSD Sata 970 GBB (System) - NVMe 980 GB (games storage) - Lenovo 27'' 144Hz - HP Reverb G2 v2 -
    WMR environment : Empty room (SkySpaces) - SteamVR resolution : 2192x2144 (48%)
    nVidia driver : 536.23

  10. #7
    Supporting Member
    Join Date
    Oct 2020
    Posts
    198
    Post Thanks / Like
    Total Downloaded
    197.43 MB

    Re: Timer and message display

    You can set a variable to set interval between messages and clean the code

    Code:
    public class Mission : AMission
    {
        //Declare stuff that is going to be used in the class
        Stopwatch MissionTimer = new Stopwatch();  // --> never used ???
        int intArrayMsg = 0; //This holds the current message number that will be displayed
        static List<string> listStrMsg = new List<string>(); //List that will hold all the messages
    	
        int intInterval = 6;  // 6 seconds between messages
        int nextTime = 0;  // by default, display 1st message immediately
    
        public override void OnBattleStarted()
        {
            base.OnBattleStarted();
            MissionTimer.Start(); // start the stopwatch
            BuildStringList(); //Run the list builder
            nextTime = MissionTimer.Elapsed.Seconds;  // can add delay here for 1st message;
            //MissionTimer.Restart(); // stopwatch reset to 0 and restart
        }
    
        public override void OnTickGame()
        {
            base.OnTickGame();
    
            if(intArrayMsg < listStrMsg.Count)  // don't go out of index
            {
               if (MissionTimer.Elapsed.Seconds >= nextTime)
               {
                   DisplayMsgToPlayer();
                   nextTime += intInterval;  // time for next message
               }
            }
        }
    
        public void DisplayMsgToPlayer() // no need index of message
        {
            GamePlay.gpHUDLogCenter("Msg ID:" + intArrayMsg + " " + listStrMsg[intArrayMsg++]);
        }
    
        static void BuildStringList() //Add each message to the list
        {
            //Looks like a 100 characters is OK to display on screen i.e.
            listStrMsg.Add("Good morning pilot, today you are going to have a lesson on starting and taking off in the Hurricane.");
            listStrMsg.Add("This is the second message...");
            listStrMsg.Add("And this is the third...");
        }
    }
    Last edited by Sleepy_Fly; Jan-31-2022 at 10:40.
    "You can teach monkeys to fly better than that!"

    Win 11 Pro - I5-12600KF - 32GB Ram - RTX 3080 TI 12GB (non OC) - SSD Sata 970 GBB (System) - NVMe 980 GB (games storage) - Lenovo 27'' 144Hz - HP Reverb G2 v2 -
    WMR environment : Empty room (SkySpaces) - SteamVR resolution : 2192x2144 (48%)
    nVidia driver : 536.23

  11. Likes GlynD liked this post
  12. #8
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Re: Timer and message display

    Thanks muchly peeps. I tried OBT~Eazy's version and it works. Yay!

    No I haven't seen the console yet, will have to find out how to display that as it will probably be pretty useful.

    ATAG_Colander you mentioned better/cleaner ways, when you have a moment I would love to see them - always looking to try and avoid spaghetti code

    Many thanks for the help both

    EDIT: Ahh just seen OBT~Eazy's post, will have a look at that as well

    Cheers
    Glyn

  13. Likes Sleepy_Fly liked this post
  14. #9
    Supporting Member
    Join Date
    Oct 2020
    Posts
    198
    Post Thanks / Like
    Total Downloaded
    197.43 MB

    Re: Timer and message display

    Must changed this in my 2nd code in the function onTickGame :

    nextTime = MissionTimer.Elapsed.Seconds + intInterval; // time for next message

    instead of :
    nextTime += intInterval;

    It's better.

    Sorry.
    "You can teach monkeys to fly better than that!"

    Win 11 Pro - I5-12600KF - 32GB Ram - RTX 3080 TI 12GB (non OC) - SSD Sata 970 GBB (System) - NVMe 980 GB (games storage) - Lenovo 27'' 144Hz - HP Reverb G2 v2 -
    WMR environment : Empty room (SkySpaces) - SteamVR resolution : 2192x2144 (48%)
    nVidia driver : 536.23

  15. #10
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Re: Timer and message display

    Thanks for that OBT~Eazy

    I will probably use it for the next iteration as I have been thinking about creating an 2-dimensional list (I looked at arrays and they look like a pain for adding new items) with the string message and then an integer value of how long the on-screen message should be displayed on-screen as I want to have a mix of long and short messages. So the code I have nabbed from somewhere else and wrangled will look a bit like these sections:

    Code:
    public class clsMsgList //create a new class to hold the 2D list
        {
            public string strMessage { get; set; } //msg
            public int intTimeOnScreen { get; set; } //time on-screen
        }
    
    static List<clsMsgList> lstMessageList = new List<clsMsgList>(); //Declare the new list item
    And then for each item I want to add in the list:

    Code:
    MsgList item = new MsgList(); //Add item 1 to the list
    item.strMessage = "Good morning pilot, today you are going to have a lesson on starting and taking off in the Hurricane.";
    item.intTimeOnScreen = 7;
    lstMessageList.Add(item);
    
    MsgList item = new MsgList(); //Add item 2 to the list
    item.strMessage = "Are you sitting comfortably?";
    item.intTimeOnScreen = 3;
    lstMessageList.Add(item);
    So the first message stays on screen for 7 seconds and the second just 3 seconds. Now I just have to work out how to pull out the bits and pieces of the list.

    EDIT: Mmm I have just found creating lists with "tuples" in C# i.e.
    Code:
    List<(string, int)> lstMessageList = new List<(string, int)>();
    lstMessageList.Add(("This is the first message", 1));
    So I can avoid having to create a new class

    If I get stuck I will give a shout out

    Cheers
    Glyn
    Last edited by GlynD; Jan-31-2022 at 13:59.

  16. Likes Sleepy_Fly liked this post
  17. #11
    Supporting Member
    Join Date
    Oct 2020
    Posts
    198
    Post Thanks / Like
    Total Downloaded
    197.43 MB

    Re: Timer and message display

    Yep, manipulate array is a pain. The tuple is a solution but if you need more parameters for messages later it's maybe not the best solution.
    Change your class is better I think.

    Why not create a constructor with params (with a default value for intTimeOnScreen) for your clsMsgList class ?

    Code:
    public class clsMsgList //create a new class to hold the 2D list
    {
            public clsMsgList(string _theMessage, int _timeOnString = 10)  // if _timeOnString is not present as parameter, use default value (10)
            {
               strMessage = _theMessage;
               intTimeOnScreen = _timeOnString;
            }
            public string strMessage; // { get; set; } not needed here
            public int intTimeOnScreen; // { get; set; } not needed here
    }
    You can do (but a little bit less readable) :

    Code:
    lstMessageList.Add(new clsMsgList("Good morning pilot, today you are going to have a lesson on starting and taking off in the Hurricane.",7));  // 7 secondes for 1st message
    lstMessageList.Add(new clsMsgList("Are you sitting comfortably?",3)); // 3 secondes for message 2
    lstMessageList.Add(new clsMsgList("Let's go!")); // default time = 10 secondes (from constructor)
    "You can teach monkeys to fly better than that!"

    Win 11 Pro - I5-12600KF - 32GB Ram - RTX 3080 TI 12GB (non OC) - SSD Sata 970 GBB (System) - NVMe 980 GB (games storage) - Lenovo 27'' 144Hz - HP Reverb G2 v2 -
    WMR environment : Empty room (SkySpaces) - SteamVR resolution : 2192x2144 (48%)
    nVidia driver : 536.23

  18. Likes GlynD liked this post
  19. #12
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Re: Timer and message display

    Ooooh I like that OBT~Eazy

    Nice and tidy, easily readable, can be customised at a later date and not a load of faffing to add items to the list. Going to use that, thank you.

    Just one question would I still use:
    Code:
    static List<clsMsgList> lstMessageList = new List<clsMsgList>(); //Create the new list item
    to initialise the list in the "public class Mission : AMission"?

    Cheers
    Glyn

  20. Likes Sleepy_Fly liked this post
  21. #13
    Supporting Member
    Join Date
    Oct 2020
    Posts
    198
    Post Thanks / Like
    Total Downloaded
    197.43 MB

    Re: Timer and message display

    Quote Originally Posted by GlynD View Post
    Ooooh I like that OBT~Eazy

    Nice and tidy, easily readable, can be customised at a later date and not a load of faffing to add items to the list. Going to use that, thank you.

    Just one question would I still use:
    Code:
    static List<clsMsgList> lstMessageList = new List<clsMsgList>(); //Create the new list item
    to initialise the list in the "public class Mission : AMission"?

    Cheers
    Glyn
    Yep, it's mandatory.
    "You can teach monkeys to fly better than that!"

    Win 11 Pro - I5-12600KF - 32GB Ram - RTX 3080 TI 12GB (non OC) - SSD Sata 970 GBB (System) - NVMe 980 GB (games storage) - Lenovo 27'' 144Hz - HP Reverb G2 v2 -
    WMR environment : Empty room (SkySpaces) - SteamVR resolution : 2192x2144 (48%)
    nVidia driver : 536.23

  22. Likes GlynD liked this post
  23. #14
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Re: Timer and message display

    Ahhh - not sure of what the required way is, to specify the item in the list i.e.

    The message: lstMessageList strMessage Number-in-list-location
    Time on-screen value: lstMessageList intTimeOnScreen Number-in-list-location.

    This is what I have so far:

    Code:
    public class Mission : AMission
    {
    
        public class clsMsgList //create a new class to hold the 2D list
        {
            public clsMsgList(string _theMessage, int _timeOnString = 5)  // if _timeOnString is not present as parameter, use default value (10)
            {
                strMessage = _theMessage;
                intTimeOnScreen = _timeOnString;
            }
            public string strMessage; // { get; set; } not needed here
            public int intTimeOnScreen; // { get; set; } not needed here
        }
    
        Stopwatch MissionTimer = new Stopwatch(); //Create a new C# timer. Need to include using System.Diagnostics;
        int intArrayMsg = 0; //This holds the current message number that will be displayed
        static List<clsMsgList> lstMessageList = new List<clsMsgList>(); //Declare the new list item - new version
        int intInterval = 0;  // This value will be updated from the array value of lstMessageList.intTimeOnScreen[ID]
        int nextTime = 0;  // by default, display 1st message immediately
    
        public override void OnBattleStarted()
        {
            base.OnBattleStarted();
            MissionTimer.Start(); // start the stopwatch
            BuildNewMsgList(); //Run the new list builder
        }
    
        public override void OnTickGame()
        {
            base.OnTickGame();
    
    
            if (intArrayMsg < lstMessageList.Count)  // all messages not displayed yet
            {
                if (MissionTimer.Elapsed.Seconds >= nextTime) //New code
                {
                    DisplayMsgToPlayer();
                    nextTime = MissionTimer.Elapsed.Seconds + lstMessageList(intTimeOnScreen[intArrayMsg]); // time for next message
                }
            }
        }
    
        public void DisplayMsgToPlayer(int intMsgToDisplay)
        {
            GamePlay.gpHUDLogCenter(lstMessageList(strMessage[intMsgToDisplay]));
            intArrayMsg++;
        }
    
        static void BuildNewMsgList()
        {
            lstMessageList.Add(new clsMsgList("Good morning pilot, today you are going to have a lesson on starting and taking off in the Hurricane.", 7));  //7 seconds for 1st message
            lstMessageList.Add(new clsMsgList("Are you sitting comfortably?", 3)); //3 seconds for message 2
            lstMessageList.Add(new clsMsgList("Let's go!")); //default time = 5 seconds (from constructor)
        }
    }
    I can find plenty of examples (googled at least a meeelllion pages ) of how to loop through the list using:

    Code:
    foreach (var item in lstMessageList)
         item.strMessage
         item.intTimeOnScreen
    But none to access a particular value!

    Can anyone help please? [Cough, cough OBT~Eazy or any C# whizzes]

    Cheers
    Glyn
    Last edited by GlynD; Feb-02-2022 at 16:19.

  24. #15
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Timer and message display

    Lists work like arrays. int x = someList[3];


    https://docs.microsoft.com/en-us/dot...1?view=net-6.0
    Last edited by ATAG_Oskar; Feb-02-2022 at 16:12.

  25. #16
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Re: Timer and message display

    Quote Originally Posted by ATAG_Oskar View Post
    Lists work like arrays. int x = someList[3];


    https://docs.microsoft.com/en-us/dot...1?view=net-6.0
    Thanks ATAG_Oskar

    So as it is a 2D multidimensional list, should that be someList[3][0] to get the msg string out of the 4th item or someList[2][1] to get the time int out of the 3rd item?

    Cheers

  26. #17
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Timer and message display

    Lists are one dimensional. You can make a list of lists but that is pointlessly complicated.

    I'd recommend you just use arrays for this hard-coded data. Another option would be a message text list and a message duration list.

    There are lots of containers in the windows API, no need to write your own.

  27. #18
    ATAG_Colander's Avatar
    Join Date
    Nov 2011
    Location
    Bir Tawil
    Posts
    11,128
    Post Thanks / Like
    Total Downloaded
    255.73 MB

    Re: Timer and message display

    Yeah, that is a 1D list that contains elements that in turn contain 2 elements. Basically like stacking wallets which each can have 2 bills inside.
    If you think that's complicated, don't try it in plain C where you have to allocate space etc.

  28. #19
    Supporting Member
    Join Date
    Oct 2020
    Posts
    198
    Post Thanks / Like
    Total Downloaded
    197.43 MB

    Re: Timer and message display

    lsttMessageList[intArray] returns a reference of an object of type clsMsgList. You have then access to properties of this object.

    to get the property intTimeOnScreen
    lstMessageList[intArrayMsg].inTimeOnScreen

    Code:
    nextTime = MissionTimer.Elapsed.Seconds + lstMessageList[intArrayMsg].intTimeOnScreen; // time for next message
    to get the property strMessage
    lstMessageList[intMsgToDisplay].strMessage

    Code:
    GamePlay.gpHUDLogCenter(lstMessageList[intMsgToDisplay].strMessage);

    But I don't understand why you use 2 index (intArrayMsg for time on screen and intMsgToDisplay for message).
    "You can teach monkeys to fly better than that!"

    Win 11 Pro - I5-12600KF - 32GB Ram - RTX 3080 TI 12GB (non OC) - SSD Sata 970 GBB (System) - NVMe 980 GB (games storage) - Lenovo 27'' 144Hz - HP Reverb G2 v2 -
    WMR environment : Empty room (SkySpaces) - SteamVR resolution : 2192x2144 (48%)
    nVidia driver : 536.23

  29. Likes GlynD liked this post
  30. #20
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Re: Timer and message display

    Edit: Just seen OBT~Eazy's post will have a look see thank you

    Cheers
    Glyn
    Last edited by GlynD; Feb-03-2022 at 04:53.

  31. #21
    Student Pilot
    Join Date
    Jun 2014
    Location
    Nr Shrewsbury
    Posts
    12
    Post Thanks / Like
    Total Downloaded
    2.5 KB

    Re: Timer and message display

    Well this seems to work an absolute treat

    Code:
    using System;
    using System.IO;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    
    public class Mission : AMission
    {
        public class clsMsgList //create a new class to hold the 2D list
        {
            public clsMsgList(string _theMessage, int _timeOnString = 5)  // if _timeOnString is not present as parameter, use default value (10)
            {
                strMessage = _theMessage;
                intTimeOnScreen = _timeOnString;
            }
            public string strMessage; // { get; set; } not needed here
            public int intTimeOnScreen; // { get; set; } not needed here
        }
    
    //Declare stuff that is going to be used in the class
        Stopwatch MissionTimer = new Stopwatch(); //Create a new timer. Uses System.Diagnostics
        int intArrayMsg = 0; //This holds the current message number that will be displayed
        static List<clsMsgList> lstMessageList = new List<clsMsgList>(); //Declare the new list item - new version
        int intInterval = 0;  // This value will be updated from the array value of lstMessageList.intTimeOnScreen
        int nextTime = 2;  // by default, display 1st message after 2 seconds
    
        public override void OnBattleStarted()
        {
            base.OnBattleStarted();
            MissionTimer.Start(); // start the stopwatch
            BuildNewMsgList(); //Run the new list builder
        }
    
        public override void OnTickGame()
        {
            base.OnTickGame();
    
            if (intArrayMsg < (lstMessageList.Count - 1))  // all messages not displayed yet
            {
                if (MissionTimer.Elapsed.Seconds >= nextTime) //New code
                {
                    DisplayMsgToPlayer();
                }
            }
        }
    
        public void DisplayMsgToPlayer()
        {
            nextTime = MissionTimer.Elapsed.Seconds + lstMessageList[intArrayMsg].intTimeOnScreen; // Update the time for next message
            GamePlay.gpHUDLogCenter(lstMessageList[intArrayMsg].strMessage + " [OS-T:" + lstMessageList[intArrayMsg].intTimeOnScreen + "]");
            intArrayMsg++; //Increment the list counter
        }
    
        static void BuildNewMsgList()
        {
            //Looks like a 100 characters is OK to display on screen i.e. msg 1 below
            lstMessageList.Add(new clsMsgList("Good morning pilot, today you are going to have a lesson on starting and taking off in the Hurricane.", 10));
            lstMessageList.Add(new clsMsgList("Are you sitting comfortably?", 5));
            lstMessageList.Add(new clsMsgList("OK, lets begin.", 4));
            lstMessageList.Add(new clsMsgList("So, welcome to your new 'Office'...", 6));
            lstMessageList.Add(new clsMsgList("You can have half a minute to look round.", 30));
            lstMessageList.Add(new clsMsgList("Right, back to work, enough gawping about!", 4));
            lstMessageList.Add(new clsMsgList("Prevent an overflow in the console.")); //default time = 5 seconds (from constructor) //This message is never shown
        }
    }
    Thanks muchly to all who have chipped in And OBT~Eazy, you have been a legend

    Will go and have a look at the mission brief screen next - another day though...

    Cheers
    Glyn
    Last edited by GlynD; Feb-03-2022 at 15:33.

  32. Likes ATAG_Colander, Sleepy_Fly liked this post

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •