hubbawubba Posted December 1, 2017 Share Posted December 1, 2017 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 More sharing options...
DavidJCobb Posted December 1, 2017 Share Posted December 1, 2017 Utility.Wait timers cannot be canceled. The running call stack will be paused for at least the specified duration. Link to comment Share on other sites More sharing options...
JonathanOstrus Posted December 1, 2017 Share Posted December 1, 2017 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 More sharing options...
foamyesque Posted December 2, 2017 Share Posted December 2, 2017 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 More sharing options...
hubbawubba Posted December 2, 2017 Author Share Posted December 2, 2017 (edited) Thank you DavidJCobb, BigAndFlabby, foamyesque for the information. It is much appreciated. I decided to go with my original solution. Edited December 2, 2017 by hubbawubba Link to comment Share on other sites More sharing options...
Recommended Posts