Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ General
➜ Client crash, issue with while loop, need a code review...
Client crash, issue with while loop, need a code review...
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Randm
(3 posts) Bio
|
Date
| Thu 13 May 2021 03:41 PM (UTC) |
Message
| I'm sure this code makes the whole client crash, but I'm not sure what is the issue.
Could you please help me out?
Thanks!
function wait_busy(cmd)
EnableGroup("wait_busy",1)
SetVariable("wait_busy_isbusy", "y")
while true do
if GetVariable("wait_busy_isbusy") == "y" then
DoAfterSpecial(0.3,'SendNoEcho("checkbusy")',12)
elseif GetVariable("wait_busy_isbusy") == "n" then
EnableGroup("wait_busy",0)
if cmd then
Execute(cmd)
end
break
else
break
end
end
end
<triggers>
<trigger
expand_variables="y"
group="wait_busy"
keep_evaluating="y"
match="^You are not busy$"
name="wait_busy_disable"
regexp="y"
script="wait_busy_disable"
send_to="12"
sequence="100"
variable="wait_busy_disable"
>
<send>SetVariable("wait_busy_isbusy", "n")</send>
</trigger>
</triggers>
| Top |
|
Posted by
| Nick Gammon
Australia (23,057 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 13 May 2021 07:16 PM (UTC) Amended on Thu 13 May 2021 10:11 PM (UTC) by Nick Gammon
|
Message
|
SetVariable("wait_busy_isbusy", "y")
while true do
if GetVariable("wait_busy_isbusy") == "y" then
...
end
end
There is nothing there to make that condition not true, thus the client will go into an infinite loop.
Despite you issuing function calls to do things after 0.3 seconds and so on, nothing else is done until the script ends. In particular, those calls to DoAfterSpecial will not do anything yet.
See http://www.gammon.com.au/forum/?id=4956 for how to make a pause. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,057 posts) Bio
Forum Administrator |
Date
| Reply #2 on Thu 13 May 2021 07:44 PM (UTC) Amended on Thu 13 May 2021 10:09 PM (UTC) by Nick Gammon
|
Message
| See http://www.gammon.com.au/forum/?id=6534 for a small timer script that you can use to break out of long loops. That can get control back to the client so you don't lose any changes you made. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Randm
(3 posts) Bio
|
Date
| Reply #3 on Thu 13 May 2021 11:01 PM (UTC) Amended on Thu 13 May 2021 11:42 PM (UTC) by Randm
|
Message
| Thanks Nick!
Especially for that small timer script. It saves a lot.
However, I still have some question for the wait.make function.
What I want to do is make an common function to check the busy status.
If I make a busy test function like this
require "wait"
function checkbusy()
wait.make(function ()
while true do
wait.time(0.3)
SendNoEcho("checkbusy")
local l = wait.regexp("^You are not busy$",3,4)
if l and string.find(l, "not busy") then
break
end
end
end)
end
can it be called in other functions? like
require "wait"
function doSomething()
wait.make(function()
do something here ...
checkbusy()
do something else ...
end)
end
| Top |
|
Posted by
| Nick Gammon
Australia (23,057 posts) Bio
Forum Administrator |
Date
| Reply #4 on Fri 14 May 2021 04:39 AM (UTC) |
Message
| The waiting is done in the inner function, not the outer one. So I think instead you could do this (not tested however):
require "wait"
function checkbusy()
while true do
wait.time(0.3)
SendNoEcho("checkbusy")
local l = wait.regexp("^You are not busy$",3,4)
if l and string.find(l, "not busy") then
break
end -- if
end -- while
end -- function checkbusy
And then:
require "wait"
function doSomething()
wait.make(function()
-- do something here ...
checkbusy()
-- do something else ...
end)
end
So "checkbusy" does the work of finding when you are not busy, however your other functions just call that to save doing it themselves every time. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
12,128 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top