Forum rules - please read before posting.

Global Time for New Game Plus (timer can be reset or paused)

Hello,

I've finished my game (The Abandoned Planet), and I want to put in a New Game Plus mode before I launch it.

The idea is this; once you finish the game the first time, you can unlock a new mode "Escape Mode". In this mode, you have to finish the game before the planet explodes. You are given 3 or 4 hours to complete the game, and a global timer counts down. This timer is always displayed on the screen in "Escape Mode". Once the time is up (if you haven't beaten the game in time), the counter stops and plays a cutscene that shows that the planet has exploded... "You Lose".

I was first really excited because I found this thread:

https://adventurecreator.org/forum/discussion/5019/global-timer

Seems easy enough, but there are some issues that I foresee, most of them have to do with the looping actionlist that runs in the background when the game starts. It's easy enough to just have it start when the game starts, and then, when you play a new game, you reset the Global Integer to 0. So, you have something like this in that actionlist that runs in the background when the game starts:

Wait 1 second > Global Integer minus 1 > Check if Global Integer is 0 and check if playing "Escape Mode" (Global Bool) > if both, then play a "You lose" cutscene > if not just keep looping.

Not a bad Idea. But....

  • Once the "You Lose" cutscene plays, the action list that runs when the game starts stops looping. How do you get it to start looping again if the player wants to try again?
  • Also, how would you expose the integer to a timer countdown? It's easy enough to connect a Unity UI TMP Label to a Global integer. But how do you make those seconds convert to hours, minutes, seconds? Custom script, I assume?

Those are my concerns at the moment. If it's all too much work, maybe a custom global timer? Maybe something else off of the asset store?

Let me know. I appreciate it. Thanks!

Jeremy

Comments

  • It's an old post - Global Timers are now an official feature. They are defined in the top toolbar's Timers Editor, and controlled using the Variable: Set Timer Action.

    Once the "You Lose" cutscene plays, the action list that runs when the game starts stops looping. How do you get it to start looping again if the player wants to try again?

    A bug currently exists whereby a completed Timer cannot be restarted. The bug report for it - along with a fix - can be found here.

    Also, how would you expose the integer to a timer countdown? It's easy enough to connect a Unity UI TMP Label to a Global integer. But how do you make those seconds convert to hours, minutes, seconds? Custom script, I assume?

    Yes, you'd need a script to handle the conversion. Something along these lines:

    https://stackoverflow.com/questions/463642/how-can-i-convert-seconds-into-hourminutessecondsmilliseconds-time

    To have it display in a Menu, you can set the result to a Global String variable and display that in the Menu instead. This can be done with:

    AC.GlobalVariables.GetVariable ("MyString").TextValue = myStringValue;
    
  • edited March 1

    Chris, thanks for letting me know. Rats -- I'm on AC 1.73.7, and I haven't updated because I have all that custom navigation stuff, and I don't want to mess it up.

    What scripts would I need to update/import just to get the timer features? Can I just import the "New" scripts, when you import from the Package Manager? Or are there other scripts that those new scripts depend upon?

    Thanks!

  • OK. I just bit the bullet and updated AC. I figured I could revert to a previous Git branch if everything broke.

    So far so good. The Global Timer feature is amazing. Great work with it. Even the "Only on Gameplay" is awesome. That's exactly what I wanted.

    One thing though -- I was using this snippet of code that you previously gave me:

    https://adventurecreator.org/forum/discussion/12452/camera-follow-cursor-global-toggle#latest

    That no longer works. Bunch of errors. Any updates I missed? Maybe this is no a feature. I look forward to hearing back. Thanks!

  • edited March 1

    One more thing. I've tried implementing your suggestion on how to convert the GlobalTimer int into a GlobalTimerString, like 00:00:00. Here is the code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System;
    
    namespace AC
    {
        public class EscapeModeTimer : MonoBehaviour
        {
            private void Update()
            {
                int globalTimer = AC.GlobalVariables.GetVariable("GlobalTimer").IntegerValue;
                TimeSpan t = TimeSpan.FromSeconds(globalTimer);
                string answer = string.Format("{0:D2}:{1:D2}:{1:D2}", t.Hours, t.Minutes, t.Seconds);
                AC.GlobalVariables.GetVariable("GlobalTimerString").TextValue = answer;
            }
        }
    }
    

    The problem here is that it only decrements the for the first second and then that's it. You can see it in the video here:

    https://www.loom.com/share/5366c1e0785e46cb9b9b1bbc57b649c6?sid=3224427c-b1bd-414b-944a-c543b6d60136

    Any help with that would be hugely appreciated.

  • The formatting isn't correct. I'm not sure exactly what, but use this to set the answer string instead:

    string answer = t.ToString (@"hh\:mm\:ss");
    

    That no longer works. Bunch of errors.

    What are the errors, exactly?

  • edited March 2

    Oh my. Once again, I'm embarrassed. I just ended up putting that influence camera stuff right after if (followCursor). That solved it. For some reason, my brain didn't work, and I put it above it. My bad.

    As for the code suggestion, I have no idea why, but that works! Chris, you rock!

    And for anyone coming to this in the future, if you want to have a Global Timer displayed as 00:00:00, here's what you can do (thanks to Chris!):

    Summary: You will be creating a Global Timer in the Timer window. That Global Timer will actually be a global int variable. And then that int variable will be converted into a string that looks like 00:00:00. Here's how to do that:

    1. Create an actionlist, select "Variable" > "Set Timer", and create a Timer. See AC documentation for more info.
    2. Create two global variables in the AC Game Editor: GlobalTimer (int) and GlobalTimerString (string).
    3. Go to back to the actionlist with the timer, and set "Global Variable" in the Timer window to the GlobalTimer (int) that you created.
    4. Create a Unity UI TextMeshPro object (this will be the visible timer associated with the string variable) and link it to a "label" on a Unity UI Menu in the AC Game Editor (Menu).
    5. In that Menu, for the label, set the label type to "Global Variable" and the global variable to the "GlobalTimerString" variable you created.
    6. Create the below script (I named it EscapeModeTimer, you name it whatever you want) and place it somewhere in your project that it will get instantiated when your game starts and will be located in "Don't Destroy On Load". I put it on the TextMeshPro object (the visible 00:00:00 label object), since Menus are in Don't Destroy on Load in AC, and since it will only be in use when that menu is needed.

    That's it. Here is the script:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System;
    
    namespace AC
    {
        public class EscapeModeTimer : MonoBehaviour
        {
            private void Update()
            {
                int globalTimer = AC.GlobalVariables.GetVariable("GlobalTimer").IntegerValue;
                TimeSpan t = TimeSpan.FromSeconds(globalTimer);
                string answer = t.ToString (@"hh\:mm\:ss");
                AC.GlobalVariables.GetVariable("GlobalTimerString").TextValue = answer;
            }
        }
    }
    

    Again, you can call it what you want. Just change where it says "EscapeModeTimer" to the name of your script.

    Thanks to Chris for helping out with this!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.