Jump to content

[HELP] Time isn't resetting


LabiVila

Recommended Posts

Posted
addEvent ("startCount", true) 
addEventHandler ("startCount", getRootElement(), 
    function () 
        ableToStart = true 
        if (ableToStart == true) then 
            addEventHandler ("onClientRender", getRootElement(), drawYourtime) 
        end 
    end 
) 
  
function handlerOnStart () 
    ableToStart = false 
    if (ableToStart == false) then 
        removeEventHandler ("onClientRender", getRootElement(), drawYourtime) 
    end 
end 
addEvent ("onClientMapStarting", true) 
addEventHandler ("onClientMapStarting", getRootElement(), handlerOnStart) 
  
function drawYourtime () 
    if not ut then 
        ut = getTickCount () 
    end 
    aut = getTickCount () 
    yourTime = formatMilliseconds (aut - ut) 
     
    dxDrawText (yourTime, 1275, 35, x, y, tocolor (255, 255, 255, 200), 1, "default-bold") 
end 

I want 'yourTime' to reset everytime the map changes, but it's actually continuing where it left off, any help?

Posted

When is startCount triggered?

Adding ut = nil in the startCount event handler could solve your problem, depending on when startCount is triggered.

Posted

Awesome, it's working :$ startCount was triggered 'onRaceStateChanging (state == "running")', however, I tried settingut = 0 but it didn't work, shouldn't it?

Posted

The way the drawYourTime checks for ut, it shouldn't work. It checks if ut is nil or not, if it is it sets ut to the current tick count. So, if ut is set to zero, it won't update its value.

if not ut or ut == 0 then 

This way it'll update it if it's equal to zero.

You could just update ut whenever the event is triggered and not worry about updating it in the drawYourTime function.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...