Originally Posted by
swaggle_pants
So I've been using wait(Integer) a lot in my scripts to wait for a screen to close or an area to load, and it seems pretty inefficient. What are some better methods for detecting changes in the environment? I'm thinking about scanning for a color in the chatbox maybe, but I'd like some ideas please!
Depends on what change you are trying to detect. If you're waiting for say, the bank screen to close, you can use waitTypeFunc, which will automatically put in a timeout failsafe for you. All the SRL-6 .isOpen functions can be used like this (bankscreen.isOpen, beastOfBurden.isOpen, etc).
waitFunc and waitTypeFunc runs a function over and over until it returns true, or the timeout expires.
If there's not an SRL-6 function, you can create your own custom function to detect an environment change, and this function will completely vary, so an example of what you're trying to detect would be great. Then you can use waitFunc like so:
Simba Code:
function environmentChange(): boolean;
begin
//your detection
if blahblahChanged then
exit(true)
else
exit(false);
end;
{...}
//somewhere else in the script
waitFunc(@environmentChange, 100 + random(100), 10000);
That code will run environmentChange() every 100 + random(100) ms, until 10000ms have elapsed OR it returns true.
If you are trying to detect "Loading - please wait" then @HKbotz created these helpful functions awhile back: https://villavu.com/forum/showthread.php?t=111436