Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, 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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Scripting loop question
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| JimW
(2 posts) Bio
|
Date
| Sun 25 Jan 2009 03:48 AM (UTC) |
Message
| I am trying to make a simple alias/script that will do the following for the MUD I play on.
There is a command in the game called goto and it can be followed by a room number..say 1000. So typing goto 1000 will teleport my character to room number 1000.
What I want to be able to do is simply type gg 100 1000 which will then send to the world:
goto 100
goto 101
goto 102
goto 103
...
all the way to goto 1000.
I am pretty sure this is a simple matter of something like:
^gg %var1 %var2
And in the send lines it will be something like
if %var1 = %var2 then end
otherwise
goto %var1
%var1 = %var1 + 1
then loop that somehow
Any help would be much appreciated. Thanks. | Top |
|
Posted by
| WillFa
USA (525 posts) Bio
|
Date
| Reply #1 on Sun 25 Jan 2009 04:24 AM (UTC) Amended on Sun 25 Jan 2009 04:25 AM (UTC) by WillFa
|
Message
| ^gg (\d+) (\d+)$
(regular expression must be checked in the add alias dialog)
local start, fin = %1, %2
local step = 1
if start > fin then step = -1 end
for i = start,fin,step do
Send ("goto " .. i)
end
This assumes that you left Lua (the default) as your scripting language. And be sure to change the Send drop down to "Script" | Top |
|
Posted by
| WillFa
USA (525 posts) Bio
|
Date
| Reply #2 on Sun 25 Jan 2009 04:35 AM (UTC) Amended on Sun 25 Jan 2009 04:41 AM (UTC) by WillFa
|
Message
| That will be the same as if you typed "goto 100;goto 101;goto102..." into the input box. Probably not very useful since you'll pop into and out of the room before you can do anything in it.
<aliases>
<alias
match="^gg (\d+) (\d+)$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>local start,fin,step = %1, %2, 1
if start > fin then step = -1 end
NextRoom = coroutine.wrap(
function ()
for i = start,fin,step do
Send ("goto "..i)
coroutine.yield()
end
NextRoom = nil
end
)
NextRoom()</send>
</alias>
<alias
match="^gg$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>if NextRoom then
NextRoom()
else
print("End of loop reached.")
end</send>
</alias>
</aliases>
Might be a little more useful. It sets up the loop, but only steps one room at a time. When you want to move to the next, "gg" by itself will step to the next room.
http://www.mushclient.com/pasting will give you instructions on what to do with the above XML if you need them. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 25 Jan 2009 04:46 AM (UTC) |
Message
| You might want to check out this page:
http://www.gammon.com.au/forum/?id=4956
That discusses building pauses into scripts.
As WillFa noted, a simple script that simply sends "goto 100" and then "goto 101" and so on, will simply fill up the output buffer with all those commands before a single one gets executed. One thing that might go wrong (amongst a few I can think of) is that the MUD might reject such a large input command. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| JimW
(2 posts) Bio
|
Date
| Reply #4 on Sun 25 Jan 2009 05:00 AM (UTC) |
Message
| Thanks!
The pause is not really necessary. Basically I am looking for some special mobs that travel around and themselves cannot be goto'd (as you can also goto mobs and players). But if I log the output of gg alias and then scan it for the mobs name then I can find them pretty easily.
Thanks again for all the help. :-) | 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.
19,475 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top