Jump to content

Problem with timers


AlvarO

Recommended Posts

I'm trying to add onClientRender event to a function for 5 seconds. When these 5 seconds has gone I want to remove it.

This is what i made

timer_1 = setTimer(showRadioSongName, 5000, 1)
timer_11 =  setTimer ( function() addEventHandler("onClientRender", getRootElement(), showRadioSongName) end, 5000, 1 )
if not isTimer(timer_1) and isTimer( timer_11 ) then
	killTimer( timer_1 )
    killTimer( timer_11 )
    removeEventHandler("onClientRender", getRootElement(), showRadioSongName)
end

 

Link to comment

Hello AlvarO,

do you want it like this?

timer_1 = setTimer(showRadioSongName, 5000, 1)
addEventHandler("onClientRender", getRootElement(), showRadioSongName)
timer_11 = setTimer ( function() removeEventHandler("onClientRender", getRootElement(), showRadioSongName) end, 5000, 1 )
if not isTimer(timer_1) and isTimer( timer_11 ) then
    killTimer( timer_11 ) 
end

By the way...

  • What is the showRadioSongName function doing? It is a function that draws dx on the screen?
  • Why are you doing line 1?

- Martin

Link to comment
1 minute ago, AlvarO said:

Hello, what I'm trying to do is output the songname of an internet radio.

showRadioSongname function is for show the message

Then I recommend just doing it like this:

addEventHandler("onClientRender", root, showRadioSongName)
setTimer(
  function()
    removeEventHandler("onClientRender", root, showRadioSongName)
  end, 5000, 1
)

This way showRadioSongName is executed for 5 seconds inside onClientRender and is removed after that.

Link to comment

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...