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
➜ Jscript
➜ \n in variables
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Chdling
(2 posts) Bio
|
| Date
| Thu 18 May 2006 05:01 PM (UTC) |
| Message
| i've got a trigger
You follow @target (?P<where>.*).
That runs (sent to script)-
x = GetTriggerWildcard ("follow", "where");
if (x == "north")
{
y = "n";
}
else if (x == "south")
{
y = "s";
}
else if (x == "east")
{
y = "e";
}
else if (x == "west")
{
y = "w";
}
else if (x == "northeast")
{
y = "ne";
}
else if (x == "northwest")
{
y = "sw";
}
else if (x == "southeast")
{
y = "se";
}
else if (x == "southwest")
{
y = "sw";
}
route = world.GetVariable("direction");
world.SetVariable("direction", route + "," + y);
So i end up with ,n,n,e,e,e etc after the trigger fires a few times (first , gets ignored by the MUD anyway)
then i wanted and alias
return -
route = world.GetVariable("direction");
world.Execute(world.ReverseSpeedwalk (route));
Now the problem here is it errors in reverse speedwalk as i have ,'s in the variable and if i try
world.SetVariable("direction", route + "\n" + y);
so everything is on it's own line (the mud will recognise n etc on it's own but won't recognise n<space>s)
it splits the code up instead of sending the next command to a newline in the variable.
So my question is either how do i send to a newline in a variable or how do i get the ReverseSpeedwalk to ignore commas but still send them? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Thu 18 May 2006 10:15 PM (UTC) Amended on Thu 18 May 2006 10:17 PM (UTC) by Nick Gammon
|
| Message
| There must be a simpler way than a huge "if" statement, like a table lookup.
Anyway, to get rid of the commas simply use a find-and-replace to get rid of them before doing the reverse speedwalk.
I'm sure Jscript will have something, and if not use MUSHclient's Replace function:
http://www.gammon.com.au/scripts/doc.php?function=Replace
However you need to fix up the multiple-character directions, like "ne" which will be interpreted as north followed by east.
MUSHclient expects such speedwalks to be rendered as "(ne)" (etc.).
See the documentation for ReverseSpeedwalk for examples of that:
http://www.gammon.com.au/scripts/doc.php?function=ReverseSpeedwalk
If you do that then you don't need the commas anyway, each direction should be recognisable on its own. That is, your built-up string should look like:
nnnee(nw)(ne)wwss(sw)
and so on.
Then you can just reverse it without any further fiddling around.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Mannoman
(7 posts) Bio
|
| Date
| Reply #2 on Fri 15 Sep 2006 08:09 PM (UTC) |
| Message
| would
while (world.GetVariable("direction").indexOf(",") > 0 ) {
var k = world.GetVariable("direction").indexOf(",") ;
text = new String(world.GetVariable("direction")) ;
text1 = new String(text.subString(0, k));
text2 = new String(text.subString(k+1, text.length);
text = text1 + text 2;
}
work to root out the , s in that string? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Sat 16 Sep 2006 12:10 AM (UTC) |
| Message
| That looks incredibly complicated. You only need to do a Replace to get rid of the commas. Try this:
s = "n,n,e,e,e,se,sw,u,d,w,n" // test string
s = world.Replace (s, ",", ")(", true) // get rid of commas
s = "(" + s + ")" // put brackets at the end
s = world.ReverseSpeedwalk (s)
Note (s) // (s)(e)(u)(d)(ne)(nw)(w)(w)(w)(s)(s)
Note (EvaluateSpeedwalk (s))
Output
s
e
u
d
ne
nw
w
w
w
s
s
As I said before you need to take into account directions like "ne" because if you just get rid of commas north followed by east (n,e) will be treated the same as northeast (ne), if you just remove the commas. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Syrin
(4 posts) Bio
|
| Date
| Reply #4 on Sat 25 Nov 2006 02:15 AM (UTC) |
| Message
| Uhm, you're saying it splits up the code... so couldn't you just double escape the newline? Like,
world.SetVariable("direction", route + "\\n" + y); | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Sat 25 Nov 2006 03:55 AM (UTC) |
| Message
| | Yes, you can double-escape the newline. I still think the big "if" statement looks messy, but if you wanted to use that, the double-escape idea should work. |
- 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.
25,314 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top