Nick Gammon said:
Personally I would be waiting for a message to say that the flask was full, rather than waiting for a certain amount of time.
When I'm buying flasks, I enable a trigger that looks for the text variations that I know are possible such as not being able to afford them:
^\>?(.*)I\'m sorry, but you don\'t have enough gold to buy that\.$|^\>?(.*)Sorry, but you can\'t afford that\.$
Or letting me know when I'm maxed out (which is the preferred and most common outcome):
^\>?You are overloaded\.$
This works fine, but if I want this to be inside of a function, the problem I'm having is that the script doesn't wait for the function to finish before moving on to the rest of the script. The reason I want to use a function is because I have many places in my script where I buy flasks, so I want to have a single function where I update that code.
function topUpFlasks()
require "wait"
wait.make (function ()
if (stopAdventuring == false) then
buyFlasks()
wait.time(buyFlasksDelay)
EnableTrigger("HealthCheckMax", true)
Send("health")
wait.time(healthCheckDelay)
countFlasksCommand()
wait.time(minorActionDelay)
EnableTrigger("HealthCheckMax", false)
if (flaskCount == 0) then
ColourNote("white", "red", "Your inventory is full. You can't carry any healing flasks. Exiting...")
allStop()
wait.time(minorActionDelay)
Send("x")
topUpFlasksReturn = true
return false
end
end
topUpFlasksReturn = true
return true
end)
end
In the above function, I've added these "topUpFlasksReturn" statements to let me know when the function is done. And then as you saw in my second post, I have a repeat-until loop waiting for topUpFlasksReturn to become true before leaving the loop. It's crude, but it seems to work in lieu of a better idea.
Nick Gammon said:
Well, how do you know that the function has finished?
Typically I know a function has finished when the function returns, but with this type of programming ... it seems as though the script moves on to the next line as soon as the function is called as opposed to waiting until the function returns.