Results 1 to 2 of 2

Thread: Test if a Timer is running?

  1. #1

    Test if a Timer is running?

    I have some code that needs a Timer that I would like to activate when certain objects enter a script zone....

    The problem I have is that if you are holding a bunch of objects or w/e the onEnter and onExit stuff triggers a heap of times... meaning I get an error saying "the timer already exists" as it trys to spawn it a bunch of times.

    So the question is how can I test to see if the timer exists and if it dose.. to not do anything?

    sudoCode
    Code:
    function onObjectLeaveScriptingZone(zone, obj)
        if zone == getObjectFromGUID('1a6c3b') then --Zone I want to test enter and exits
            local timerID = self.getGUID()..math.random(9999999999999)
            IF TIMER IS NOT RUNNING THEN --<---- How cand I do this line? 
                timerSpawn = true
                Timer.create({identifier=timerID, function_name="countItems", function_owner=self,
                repetitions=5, delay=1})
            END
        end
    end
    I know I could spawn a zillion timers with unique names but would prefer to do it this way.

    PS - Is there a way to put a callback.. so it runs a function after the timer has stopped its repetitions?
    My Boardgame uTube chan - Tragic's Table Top
    BGG Guild of BoardGame uTubers - Tube Tables

  2. #2
    Join Date
    May 2016
    Posts
    1,072
    There's only create and destroy, no check I'm afraid. But hacks get you where you need to go.

    If you put a destroy before a create, even if there is nothing to destroy, the destroy will not error or cause any issue. So this would allow you to "start" the same time a dozen times at once and only have it end once. However it has the downside of restarting the timer.

    To get around this, you can just use a variable bool. Do an if timerRunning then check. If not, start the timer and timerRunning=true. When the timer function triggers, timerRunning=nil. There, now the timer can only start if the timer isn't running. Check timerRunning at any time to see if that timer is running.

Similar Threads

  1. Getting ready for my first time running DnD in tabletop
    By cerin616 in forum General Discussion
    Replies: 3
    Last Post: 04-20-2017, 08:29 PM
  2. Running several coroutines in strict order?
    By Nightgaunt in forum Scripting
    Replies: 6
    Last Post: 07-21-2016, 07:08 PM
  3. [SOLVED] Incorrect Version Game running on V7. 3 instead of V7.6. Cannot Update
    By maur_maur in forum Technical Support
    Replies: 1
    Last Post: 07-06-2016, 09:39 AM
  4. Running into a camera problem after recent patch
    By RazeDevastator in forum Bug Reports
    Replies: 1
    Last Post: 04-08-2016, 04:07 PM
  5. [SOLVED] Mac Build not Running
    By bethany7 in forum Technical Support
    Replies: 1
    Last Post: 03-21-2014, 02:36 PM

Posting Permissions

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