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
➜ Walking script help?
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Zombero
(2 posts) Bio
|
Date
| Sun 05 Sep 2004 09:50 PM (UTC) |
Message
| I have little to no scripting experience so I was wondering if someone could help me make a fairly simple script. I'm trying to make a script that will go in a random direction (east west south north) other than the direction that it came from. It would also need to somehow recognize a deadend and go in that case go back the direction it came from. The exits in the world show up between the colon and ] in [exits: ] and are seperated by commas.
example: [exits: west, north, south, east]
It would also need to go down when down is an availble exit and stop the script on a certain output from the world. Can anyone provide me with or help me make a script like this for Mush Client? Thanks. | Top |
|
Posted by
| Jlzink
USA (15 posts) Bio
|
Date
| Reply #1 on Mon 06 Sep 2004 12:58 AM (UTC) |
Message
| Trigger: [exits: *]
Label: Walk
Script: Walk
[exits: west, north, south, east]
in a *.vbs file
Dim LastDir as String
Sub Walk(a,b,directions)
dim s as string
s = split(directions,", ")
getnewdir = rnd * ubound(s)
if s(getnewdir) <> LastDir then
world.send s(getnewdir)
LastDir = s(getnewdir)
end if
end sub
or something similar to that.
To tired to think to hard....worked to much. | Top |
|
Posted by
| Zombero
(2 posts) Bio
|
Date
| Reply #2 on Mon 06 Sep 2004 02:20 AM (UTC) Amended on Mon 06 Sep 2004 07:20 AM (UTC) by Zombero
|
Message
| Okay, it took a bit of tweeking but I got that to work :). Thanks. | Top |
|
Posted by
| Shadowfyr
USA (1,790 posts) Bio
|
Date
| Reply #3 on Mon 06 Sep 2004 07:49 AM (UTC) Amended on Mon 06 Sep 2004 07:52 AM (UTC) by Shadowfyr
|
Message
| The briliant minds and MS, in order to make things easier for them, rather than the coder, chose to impliment variables in the script as type 'variant'. This didn't need to be a major disaster, except that to simplify things even farther, they have the variables 'auto-cast' themselves into the new type. If you do:
a = 1
a = a & "g"
then instead of an error, since the internal type of 'a' is in fact integer, it instead converts 'a' into a string type internally and appends the new value. Oops! This gets even more fun when supposedly perfectly valid values like " 32" fail to cast to integer, bacause the extra space they contain automatically causes them to be cast to string. The following 'will' cause an error:
a = " 32"
a = a - 3
If you use '+' it simply assumes you meant & and concatinates them. Basically there are no explicit types and some fun things are missing, like conversion of any integer value into a date, though you can do the reverse. Why they left that one out I am not sure. It is bloody hard to add X days, hours, etc. to a date when the function doesn't exist. :( In any case, when it isn't 100% sure what you intended, it guesses and recasts to what it 'thinks' you wanted to have. If you want explicit casting, try something other than VBScript. :p It is brain dead in some respects imho, but it is still less cryptic than the alternatives in a lot of ways. You just have to learn to live with the stuff they chose to cut out of it to turn it into a script system.
Of course, VB does these odd things with variables too, but only if you intentionally leave off the 'as <type>' for use with OLE automation. | Top |
|
Posted by
| Mushclientuser
(8 posts) Bio
|
Date
| Reply #4 on Sat 05 Nov 2005 09:00 PM (UTC) |
Message
| Anyone know how to do this for Lua script?? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #5 on Sun 06 Nov 2005 02:34 AM (UTC) Amended on Tue 06 May 2008 09:36 PM (UTC) by Nick Gammon
|
Message
| This trigger would do it, although it doesn't remember which way you walked, it shows the general idea ...
<triggers>
<trigger
enabled="y"
match="[exits: *]"
send_to="12"
sequence="100"
>
<send>
-- split exits into a table at the comma
exits = {}
for w in string.gmatch ("%1", "[^,]+") do
table.insert (exits, w)
end -- for
-- choose one randomly
which = (math.floor (MtRand () * table.getn (exits))) + 1
-- go that way
Send (Trim (exits [which]))
</send>
</trigger>
</triggers>
[EDIT] Edited on 7 May 2008 to change string.gfind to string.gmatch. Version 3.80 of MUSHclient switched from Lua version 5.0 to Lua version 5.1, which requires this change. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Mushclientuser
(8 posts) Bio
|
Date
| Reply #6 on Sun 06 Nov 2005 10:28 PM (UTC) |
Message
| i'm just bouncing between 2 rooms.. and not moving in a random direction... | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #7 on Mon 07 Nov 2005 02:29 AM (UTC) |
Message
| What, it randomly just sends east, west, east, west, like that? And you keep bouncing back and forth? Strange. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Mushclientuser
(8 posts) Bio
|
Date
| Reply #8 on Mon 07 Nov 2005 10:38 PM (UTC) |
Message
| ok my exits are: for example..
[Exits: south, north, east]
i don't know what the trigger does but i see
south north east echoed below the [Exits: ... ...]
and so i will go south,
but if the next room's exits are
[Exits: north, south, east]
then what is echoed is: north south east
and i go north.. the same thing happens in the first room and so i end up going north and south
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #9 on Mon 07 Nov 2005 11:40 PM (UTC) Amended on Tue 06 May 2008 09:36 PM (UTC) by Nick Gammon
|
Message
| How long did you try this for? Certainly, if you move randomly you may end up back where you came. If there are 3 exits you have a 1 in 3 chance of going back. However with a bit more complexity you can avoid that.
<triggers>
<trigger
enabled="y"
match="[Exits: *]"
send_to="12"
sequence="100"
>
<send>
-- table of inverse directions
inverse = {
north = "south",
south = "north",
east = "west",
west = "east",
up = "down",
down = "up",
ne = "sw",
sw = "ne",
se = "nw",
nw = "se",
} -- end of table of inverse directions
-- split exits into a table at the comma
exits = {}
for w in string.gmatch ("%1", "[^,]+") do
table.insert (exits, w)
end -- for
number_of_exits = table.getn (exits)
repeat
-- choose one randomly
which = (math.floor (MtRand () * number_of_exits)) + 1
direction = Trim (exits [which])
until direction ~= inverse [last_direction] or number_of_exits == 1
-- go that way
Send (direction)
-- remember it so we don't go back
last_direction = direction
</send>
</trigger>
</triggers>
What this version does is remember the last direction it sent, and then make sure it doesn't follow it by the inverse direction (see table above).
In other words, if it sends "north" it won't follow it by "south" next time.
However there is a test for if the number of exits is 1, in which case you are in a dead-end room, and the only way out is the way you came.
[EDIT] Edited on 7 May 2008 to change string.gfind to string.gmatch. Version 3.80 of MUSHclient switched from Lua version 5.0 to Lua version 5.1, which requires this change.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Aromaros
(9 posts) Bio
|
Date
| Reply #10 on Mon 28 Jan 2008 07:52 PM (UTC) |
Message
| How do I go about using this? Do I put it in as a trigger or a script? If it is a script, what language is it? I'm somewhat new to all this... Thank you | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #11 on Mon 28 Jan 2008 08:01 PM (UTC) |
Message
| It is a trigger with scripting in the send box.
See http://www.mushclient.com/pasting for how to use the example there.
The language is Lua, which is the default scripting language. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Orangeist
(8 posts) Bio
|
Date
| Reply #12 on Tue 06 May 2008 09:09 AM (UTC) |
Message
| For reference, if you want to use this script, make sure to replace string.gfind with 'string.gmatch'. Calling string.gfind will raise an error. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #13 on Tue 06 May 2008 09:37 PM (UTC) |
Message
| Thanks for the notification. I have amended the posts above to reflect this. The original posts were for Lua 5.0, however Lua 5.1 has been around for a while now. |
- 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.
37,107 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top