Register forum user name Search FAQ

Gammon Forum

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 ➜ Speedwalking in a hostile environment

Speedwalking in a hostile environment

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


Posted by Tamalak   (7 posts)  Bio
Date Sun 03 Jun 2001 07:18 PM (UTC)

Amended on Sun 03 Jun 2001 09:53 PM (UTC) by Nick Gammon

Message
I am attempting to make a speedwalking script in a MUD that is highly resistant to scripting and has many clever safeguards. Normally it would simply be a matter of making an alias with ALL the directions from point A to point B, but the obstacles in this particular MUD include:

---> A 5-command buffer limit, that deletes any commands entered if there are already 5 non-resolved commands entered.

---> The ability for hostile NPCs to occasionally 'block me from leaving!' and cancel a direction command.

---> The possibility that gates through which I attempt to move are closed or locked in which case "open gate" and "unlock gate <ENTER> open gate" are needed, respectively.

Here is the code I have come up with in its current nightmarish, spagetti form:

WARNING: ATTEMPTING TO READ THE FOLLOWING MAY RESULT IN SPONTANEOUS FORMATION OF BRAIN TUMORS. DO SO AT YOUR OWN RISK.


sub squarelair
    world.addtrigger "counter", "Obvious paths", "", 33, -1, 0, "", "counter"
    world.addtrigger "counter2", "Obvious exits", "", 33, -1, 0, "", "counter"
    world.addtrigger "movement2", "blocks you from leaving!", "", 33, -1, 0, "", "movement"
    world.addtrigger "opengate", "It's closed!", "open gate", 33, -1, 0, "", "movement"
    dim glide
    glide = world.getvariable("glide")
    glide = 0
    world.setvariable "glide", glide
end sub

sub lairsquare
    world.addtrigger "counter", "Obvious paths", "", 33, -1, 0, "", "bcounter"
    world.addtrigger "counter2", "Obvious exits", "", 33, -1, 0, "", "bcounter"
    world.addtrigger "movement2", "blocks you from leaving!", "", 33, -1, 0, "", "bmovement"
    world.addtrigger "opengate", "It's closed!", "open gate", 33, -1, 0, "", "bmovement"
    dim glide
    glide = world.getvariable("glide")
    glide = 0
    world.setvariable "glide", glide
end sub

sub counter (strTriggerName, strTriggerLine, arrWildCards)
    dim glide
    glide = world.getvariable("glide")
    glide = glide + 1
    world.setvariable "glide", glide
    if (glide = 1) or (glide = 2) or (glide = 3) or _
       (glide = 4) or (glide = 5) or (glide = 6) or _
       (glide = 8) or (glide = 9) or (glide = 11) or _
       (glide = 12) or (glide = 15) or (glide = 16) or _
       (glide = 17) or (glide = 18) or (glide = 19) or _
       (glide = 20) or (glide = 21) or (glide = 23) or _
       (glide = 24) or (glide = 25) or (glide = 28) or _
       (glide = 29) or (glide = 30) or (glide = 32) or _
       (glide = 45) or (glide = 46) then
    world.send "s"
    end if
    if (glide = 7) or (glide = 22) or (glide = 33) or _
           (glide = 40) or (glide = 43) then
    world.send "go gate"
    end if
    if (glide = 10) or (glide = 26) or (glide = 27) or _
       (glide = 31) or (glide = 34) or (glide = 35) or _
       (glide = 36) or (glide = 37) or (glide = 38) or _
       (glide = 39) or (glide = 41) or (glide = 42) then
    world.send "sw"
    end if
    if (glide = 13) or (glide = 14) or (glide = 47) or _
           (glide = 48) then
    world.send "se"
    end if
    if (glide = 44) then
    world.send "go bridge"
    end if
    if glide = 48 then
    world.deletetrigger "counter"
    world.deletetrigger "counter2"
    world.deletetrigger "movement2"
    world.deletetrigger "opengate"
    end if
end sub

sub movement (strTriggerName, strTriggerLine, arrWildCards)
    dim glide
    glide = world.getvariable("glide")
    if (glide = 1) or (glide = 2) or (glide = 3) or _
       (glide = 4) or (glide = 5) or (glide = 6) or _
       (glide = 8) or (glide = 9) or (glide = 11) or _
       (glide = 12) or (glide = 15) or (glide = 16) or _
       (glide = 17) or (glide = 18) or (glide = 19) or _
       (glide = 20) or (glide = 21) or (glide = 23) or _
       (glide = 24) or (glide = 25) or (glide = 28) or _
       (glide = 29) or (glide = 30) or (glide = 32) or _
       (glide = 45) or (glide = 46) then
    world.send "s"
    end if
    if (glide = 7) or (glide = 22) or (glide = 33) or _
           (glide = 40) or (glide = 43) then
    world.send "go gate"
    end if
    if (glide = 10) or (glide = 26) or (glide = 27) or _
       (glide = 31) or (glide = 34) or (glide = 35) or _
       (glide = 36) or (glide = 37) or (glide = 38) or _
       (glide = 39) or (glide = 41) or (glide = 42) then
    world.send "sw"
    end if
    if (glide = 13) or (glide = 14) or (glide = 47) or _
           (glide = 48) then
    world.send "se"
    end if
    if (glide = 44) then
    world.send "go bridge"
    end if
    if glide = 48 then
    world.deletetrigger "counter"
    world.deletetrigger "counter2"
    world.deletetrigger "movement2"
    world.deletetrigger "opengate"
    end if
end sub

sub stopit
    world.deletetrigger "counter"
    world.deletetrigger "counter2"
    world.deletetrigger "movement2"
    world.deletetrigger "opengate"
end sub


Top

Posted by Tamalak   (7 posts)  Bio
Date Reply #1 on Sun 03 Jun 2001 07:18 PM (UTC)
Message
When I am in the 'square' and want to go to the 'lair', I simply type /squarelair and 'look' at the room I'm in. Part of every room description is either "Obvious paths" or "Obvious exits" but never both. /squarelair creates and activates the nessesary triggers and creates a numeric variable called 'glide' that keeps track of where I am. The status of 'glide' determines which direcion I go in next. Whenever I enter a new room, it is automatically 'looked' at and 'glide' is incremented. The current form is barely functional, and its problems are numerous and open-ended:

---> The efficient programmer will be horrified to notice that /movement and /counter are EXACTLY THE SAME PROGRAM, except /counter increments glide and /movement does not. /movement is called when I run into a problem ('blocks you from leaving!', etc) and my character was not able to advance last time and must try again. How does one call a subroutine from another subroutine? I looked in the HELP file; "How Subs are Called", and it did not mention this method. Knowing how to call the subs will cut the amount of code almost in half.

---> The code displayed is for a single round-trip. If I want to make speedwalking for another trip, I have to create differently named 'counter', 'movement', 'squarelair', and 'lairsquare' programs with essentially the same code, but different 'glide' commands. I only have a few of them, but they are already cluttering my Notepad. Are matrixies or lists (one-dimentional matrixies) supported in MUSHclient? It would be wonderful if I could simply store all the 'glide' information in a simple list (1=north, 2=east, etc), and direct all speedwalking subs to the same 'movement' and 'counter' programs.


---> Is there an easier (shorter) way to make the 'if' statements? "if glide = 1/2/4/6/7/9/21/23 then", or somesuch? Do you have any more suggestions on how to make this more efficient and easy to make? Many thanks in advance for anyone with the bravery to adopt this tortured code!

---> (not directly related to the code): Is there any way to enter multiples lines at once without physically using <Enter>? In zMUD, for instance, if one enters in the input window "go east;kill goblin", "go east" and "kill goblin" are entered in separately. This would be useful in programming as well, as aliases or 'world.send's with many commands could be entered in one line, ie:

world.send 's;s;s;s;go gate;s;s;sw;s;s;se;se' instead of

world.send 's'
world.send 's'
world.send 's'
world.send 's'
world.send 'go gate'
world.send 's'
.
.
.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Sun 03 Jun 2001 09:33 PM (UTC)
Message
I have reformatted your script a bit with underscores to make it a bit more readable on the web page. You can use an underscore to continue a line (eg. an IF).


Now, to answer your questions ...

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Sun 03 Jun 2001 10:18 PM (UTC)

Amended on Sun 03 Jun 2001 10:19 PM (UTC) by Nick Gammon

Message
Quote:

How does one call a subroutine from another subroutine?


Simply make another subroutine and 'call' it, eg.


sub DoGlide (arg1, arg2)
... blah ...
end sub



and elsewhere ...


call DoGlide (2, 3)



Quote:

Are matrixies or lists (one-dimentional matrixies) supported in MUSHclient?


You can use DIM to set up an array.


dim myarray (100)


Quote:

Is there an easier (shorter) way to make the 'if' statements? "if glide = 1/2/4/6/7/9/21/23 then", or somesuch?


One way is with "select case" - here is an example from the VBscript help:


Select Case MyVar
Case "red" document.bgColor = "red"
Case "green" document.bgColor = "green"
Case "blue" document.bgColor = "blue"
Case Else MsgBox "pick another color"
End Select


In your case you might want to make a little function. Here is an example of what you could do:



Function CheckList (mylist, whichitem)
Dim listitems
Dim i

listitems = split (mylist, ",")

for i = lbound (listitems) to ubound (listitems)

if cint (listitems (i)) = whichitem then
  CheckList = true
  exit function
end if

next

CheckList = false
end function




Then you can do this:

if checklist ("1, 2, 3, 4", 4) then
... blah ...
end if

What "checklist" does is take a string consisting of numbers separated by commas, splits them at the comma, and then walks the list to see if the supplied number (in this case 4) is in the list.

That would simply your IF's a bit.

Quote:

Is there any way to enter multiples lines at once without physically using <Enter>?


In the command window itself you can type Ctrl+Enter to enter a multi-line command.

Also you can turn on command-stacking for keyboard input and nominate a stack character (eg. ";"). However this will not work in world.send.

In a script you could do this:


world.send 'south' + vbcrlf + 'north' + vbcrlf + 'down'


and so on, or you could make a function like the one above that did a "split" at a semicolon.

eg.



Sub CommandSplit (commands)
Dim listitems
Dim i

listitems = split (commands, ";")

for i = lbound (listitems) to ubound (listitems)
 world.send listitems (i)
next

end sub



Then you could type (in a script):

commandsplit "north;west"




- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #4 on Sun 03 Jun 2001 10:23 PM (UTC)
Message

Also, check out this forum post, which describes something similar to what you are doing, except in a more general way ... Auto Walker


- 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.


20,752 views.

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

Go to topic:           Search the forum


[Go to top] top

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