[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Scripting loop question

Scripting loop question

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by JimW   (2 posts)  [Biography] 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.
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] 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"
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] 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 &gt; 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by JimW   (2 posts)  [Biography] 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. :-)
[Go to top] 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.


17,211 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]