Jump to content

[LE] Trying to cancel a Wait timer, the best way.


hubbawubba

Recommended Posts

Hi, I am trying to modify this mod with Utility.Wait timers. I want to be able to interrupt or cancel the timer at any given moment. I have tried adding the Utility.Wait within a function registered by RegisterForModEvent and at one point on event, unregister it, that did not help. The, only way I know that (I have not tested) is dividing the timer Wait into smaller Waits and polling a variable to cancel the wait. Though, I want to know if there is a better more efficient way, that does not require me to repeat the tiresome procedure for all Utility.Wait s within the mod.

 

Regards and thanks.

Link to comment
Share on other sites

Like DavidJCobb said, waits cannot be cancelled. Like you suggested in the OP you could use a small wait with a loop and counter to simulate the same wait. Adding in an additional check if you want to keep waiting or not. It's not super efficient to do so but it's the only method aside from using a game timer to call back. And then implement some way of cancelling the game timer. Keep in mind that using a loop with waits and then doing some sort of logic check will cause the wait duration to have some inaccurate latency. The waits will be accurate but you'll have additional processing time for the logic check.

Link to comment
Share on other sites

The waits themselves are not necessarily accurate either; you will wait for at least that duration, but latency in processing threads can cause the time to be significantly longer than anticipated.

 

If the idea is to do something after a certain interval, but not if interrupted, a better course is probably RegisterForSingleUpdate, which can be cancelled or the event thrown out through any of a variety of methods.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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