Thread Tools Display Modes
05/27/15, 06:07 PM   #1
Luxor
 
Luxor's Avatar
Join Date: May 2015
Posts: 7
Question 10 Min (Dolmens Timer) - Help Request

So after three days of learning how to use lua and xml, I'm still very much lost when it comes to actually creating something of my own.

What I'm trying to do is create a 10min timer (doesn't matter whether its counting up or down). I'm currently working with seconds as minutes seem a bit complicated as I think i'd have to display the active conversion of minutes from seconds, which itself is already out of my present abilities.

At the moment, I have a functional counter synced to GetFrameDeltaTimeSeconds() every time my addon updates however, GetFrameDeltaTimeSeconds() seems to be 3x the speed of actual seconds on a clock. It's still better than updating every frame but it still isn't what I want it to be.
My current codes are:

Timer.lua

Lua Code:
  1. local counter = 0
  2. local delta = GetFrameDeltaTimeSeconds()
  3.  
  4. function TimerUpdate()
  5.     TimerCounter:SetText(string.format("Timer: %0.2fs", counter))
  6.     counter = counter + delta
  7. end
  8.  
  9. function TimerInitalized()
  10. end


Timer.xml
Code:
<GuiXml>
    <Controls>
        <TopLevelControl name="Timer">
            <Dimensions x="200" y="42" />
            <Anchor point="CENTER" />
 
            <OnUpdate>
                TimerUpdate()
            </OnUpdate>
 
            <OnInitialized>
                TimerInitialized()
            </OnInitialized>
 
            <Controls>
                <Backdrop name="$(parent)BG" inherits="ZO_ThinBackdrop" />
                <Label name="$(parent)Counter" font="ZoFontWindowTitle" color="CFDCBD" wrapMode="ELLIPSIS" verticalAlignment="CENTER" text="Timer: ">
                    <AnchorFill />
                </Label>
            </Controls>
        </TopLevelControl>
    </Controls>
</GuiXml>
Also I wouldn't even know how to get it to stop once it reached 600secs (10 mins).

In pure Lua it would look something like this:

Lua Code:
  1. function sleep(s)
  2.   local atime = os.time() + s
  3.   repeat until os.time() > atime
  4. end
  5.  
  6. Time = 0
  7.  
  8. for i=Time, 599 do
  9.     print (i + 1)
  10.     sleep(1)
  11. end

However, I don't know how to even implement something like that into ESO.

All help is appreciated.

Thanks in advance!

Last edited by Luxor : 05/27/15 at 06:49 PM.
  Reply With Quote
05/27/15, 06:12 PM   #2
QuadroTony
Banned
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 828
btw regular dolmen not 10 but 13 min cooldown
  Reply With Quote
05/27/15, 06:17 PM   #3
Luxor
 
Luxor's Avatar
Join Date: May 2015
Posts: 7
Originally Posted by QuadroTony View Post
btw regular dolmen not 10 but 13 min cooldown
I've only been playing ESO for less than a month so you're probably right however, according to Tamriel Foundry:

All anchors have a 10 minute reset time, from either after the 5th center pinion was destroyed (see below), or they self-destruct.
  Reply With Quote
05/27/15, 10:23 PM   #4
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
Take at these two functions:
Lua Code:
  1. timestamp = GetTimeStamp()
  2. elapsedSeconds = GetDiffBetweenTimeStamps(now, start)

Also, for running the update code, you can use
Lua Code:
  1. EVENT_MANAGER:RegisterForUpdate("MyTimerUpdate", 1000, updateCallback)
  Reply With Quote
05/27/15, 11:20 PM   #5
Luxor
 
Luxor's Avatar
Join Date: May 2015
Posts: 7
Red face

So I tried doing what you said but I'm afraid I'm utterly lost.

My current .lua file looks like this:
Lua Code:
  1. timestampA = GetTimeStamp("start")
  2. timestampB = GetTimeStamp("now")
  3. elapsedSeconds = GetDiffBetweenTimeStamps(now, start)
  4. counter = 1
  5.  
  6. function TimerUpdate()
  7. TimerCounter:SetText(string.format("Timer: %d", elapsedSeconds))
  8. counter = counter + elapsedSeconds
  9. end
  10.  
  11. function TimerInitalized()
  12. end

I'm certain that my code above is not even close to being correct and as for the event trigger, I'm not exactly sure how to implement it as my knowledge on custom events and callbacks is extremely limited.

Y' know the saying teach a man to fish and all that...

Well I thought it was a good idea to sail straight off into the middle of the Pacific Ocean to teach myself to fish...I didn't catch a single thing and I drowned miserably.

I think I'll just lick my wounds and try fishing at a pond for the moment.

Last edited by Luxor : 05/27/15 at 11:24 PM.
  Reply With Quote
05/28/15, 02:06 AM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
I think you are mistaken about how these two methods work.

GetTimeStamp does not take an argument (why should it even know what "start" and "now" means?).
It returns the current time when you call it like os.time() would do.

GetDiffBetweenTimeStamps is just an arithmetic function and returns the difference between stamps.

So what you want to do is call GetTimeStamp when you start your timer and save it as your start time and then every update you call it again and get the elapsed time with GetDiffBetweenTimeStamps.

Here some untested code:
Lua Code:
  1. local startTime
  2. local TIMER_LENGTH = 60*10 -- 10 minutes
  3.  
  4. local function HandleUpdate()
  5.   local now = GetTimeStamp()
  6.   local elapsedSeconds = GetDiffBetweenTimeStamps(now, startTime)
  7.   TimerCounter:SetText(string.format("Timer: %d", elapsedSeconds))
  8.   if elapsedSeconds >= TIMER_LENGTH then -- we can stop the updates once we have reached our end time
  9.     EVENT_MANAGER:UnregisterForUpdate("MyUniqueUpdateHandleName")
  10.   end
  11. end
  12.  
  13. local function StartTimer()
  14.   startTime = GetTimeStamp()
  15.   EVENT_MANAGER:RegisterForUpdate("MyUniqueUpdateHandleName", HandleUpdate)
  16. end
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » 10 Min (Dolmens Timer) - Help Request


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off