LUA Sleep Function?

I’d like to create a simple script to remove the marker over my head, since people keep doing that, and I don’t like it. Rather than having an argument over it, I figure it’s better to just have a script remove it.

I think it should be fairly straightforward: Just run the command, wait a second, then run it again, loop infinitely. I’m not familiar with LUA, but I did some searching, and it sounds like there’s no in-built Sleep function in the language. The searches I found suggested using an OS command or Library to do so. However, given that this is running inside warcraft, I don’t know what is available.

I’m thinking something like this:

 while true do
     /tm [@player,nocombat] 0
     sleep 1
 end

But what do I put in for the sleep function? Can someone point me in the right direction? Maybe there’s some documentation on this?

The UI is single-threaded. A conventional sleep for 1 second would be locking up your client for one second.

In WoW you don’t want think in terms of “how can I wait for x seconds before resuming?” but instead “how do i come back to this task in x seconds?”.

There’s numerous ways (can even get fun with yielding coroutines but you’re still bound by the single-threadedness of the UI), but a common built-in one that doesn’t require frames for OnUpdates and such is C_Timer.

/run C_Timer.NewTicker(1,function() SetRaidTarget("player",0) end)

If you run that (I recommend only hitting it once, if you run it again it will start a new ticker without stopping old), it will run the code every second.

NewTicker returns a handle you can use to stop it to start another.

The UI is very event driven. You’re probably better off turning it into a small addon or weakaura that reacts to the RAID_TARGET_UPDATE event to instantly remove it whenever it gets applied.

Interesting! I hadn’t thought about that. Thank you for your help. Your code worked perfectly!

I’d thought of an addon, but it seemed like overkill. A weakaura script is a very interesting idea, thank you!