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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Make alias
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Make alias

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


Pages: 1 2  

Posted by Halig   Portugal  (123 posts)  [Biography] bio
Date Wed 04 Feb 2015 02:39 PM (UTC)
Message
Hi to all. I have a question, i've been killing my mind to try to figure this out, and i can't.
I have an alias, like this:
-stringo -(.*) -(.*) -(.*) -(.*)

What it does is the following:

var item;
var newitem;
var short;
var long;

item = "%1";
newitem = "%2";
short = "%3";
long = "%4";

world.send("string obj " + item + " name " + newitem);
world.send("string obj " + newitem + " short " + short);
world.send("string obj " + newitem + " long " + long);

My problem is that if the name (newitem) has 2 or more words, the code gives an error.
Example: The newitem will have the name mighty hammer gods.
When it does the short description on it, it gets the full name, mighty hammer gods, and not only one of the names. What i need is a line of code, that if it has one keyword, it uses that keyword, if it has 2 keywords, it sets the name to those 2 keywords, but when doing the short or the long, it uses only one of those keywords. And so on, if it has 3 the same thing.
What am i doing wrong?
Thank you.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 04 Feb 2015 08:02 PM (UTC)
Message
It would help to post the exact alias, and the exact text that causes it to fail.

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


However I am guessing you need to make the wildcards "non greedy" by adding a ?, like this:


 -stringo -(.*?) -(.*?) -(.*?) -(.*?)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] bio
Date Reply #2 on Wed 04 Feb 2015 08:53 PM (UTC)
Message
<aliases>
<alias
match="-stringo -(.*?) -(.*?) -(.*?) -(.*?)"
enabled="y"
expand_variables="y"
group="Restring"
regexp="y"
send_to="12"
keep_evaluating="y"
sequence="100"
>
<send>var item;
var newitem;
var short;
var long;

item = "%1";
newitem = "%2";
short = "%3";
long = "%4";

world.send("string obj " + item + " name " + newitem);
world.send("string obj " + newitem + " short " + short);
world.send("string obj " + newitem + " long " + long);</send>
</alias>
</aliases>

It is used for restring objects on the MUD. I don't know if all MUD's are alike.
The error is that on the second world.send, the newitem can only have one word, and not more then one word. If i name the item like i sayd before, the string saved on the var new item will be the all name, and i only need one, the first word for example.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 05 Feb 2015 05:24 AM (UTC)
Message
Can you please post an example of the MUD output that this should be matching on? Then I can test it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] bio
Date Reply #4 on Thu 05 Feb 2015 07:07 AM (UTC)

Amended on Thu 05 Feb 2015 07:08 AM (UTC) by Halig

Message
N:Reorx Vnum:1205 Incog: Wizi:
-stingo -book -book pedro -book pedro -Here lies a book
Huh?

N:Reorx Vnum:1205 Incog: Wizi:
string obj book name book pedro
string obj [b]book pedro[/b] short book pedro
string obj [b]book pedro[/b] long Here lies a book.

N:Reorx Vnum:1205 Incog: Wizi: Syntax:
string char <name> <field> <string>
fields: name short long desc title spec racetext
string obj <name> <field> <string>
fields: name short long extended

N:Reorx Vnum:1205 Incog: Wizi: Syntax:
string char <name> <field> <string>
fields: name short long desc title spec racetext
string obj <name> <field> <string>
fields: name short long extended

N:Reorx Vnum:1205 Incog: Wizi:


This is the MUD output. The two last outputs are the error, that's why i can't do what it suposed to do.
Thank you Nick.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 05 Feb 2015 08:09 AM (UTC)
Message
Nothing in your last post has "stringo" in it.


 match="-stringo -(.*?) -(.*?) -(.*?) -(.*?)"

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] bio
Date Reply #6 on Thu 05 Feb 2015 08:33 AM (UTC)
Message
Nick,

I have posted all the outputs. I don't know what to do more :(.

The commands on the MUD are as followed:

string obj (object) name (new name)
string obj (new name) short (short description)
string obj (new name) long (long description)

These are the commands that are inputed on the MUD, so you can change the name of the object. The () are there only to show that it is what you need to input.
So i need to make an alias to do those 3 commands, in Jscript or with something else. See the (new name) that's where my problem is. If you set the new name with one word, there is no problem, but if you put 2 words on the new name, the second command don't work cause the (new name) must be entered on only one word. If i do those 3 commands, separated, by hand, they work fine.
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #7 on Thu 05 Feb 2015 08:41 AM (UTC)

Amended on Thu 05 Feb 2015 08:48 AM (UTC) by Meerclar

Message
He's trying to match that to his input rather than mud output Nick. At least I'm pretty sure that's what I'm reading in his next to last post.


Halig, try putting your newitem output in quotes if it contains multiple words. What codebase is this for? Would be a good bit easier to help you with that info.

ex: string obj "(multi-word new name)" short (short description)

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] bio
Date Reply #8 on Thu 05 Feb 2015 09:12 AM (UTC)
Message
Hi Meerclar,

You are right. I'm trying to match my input, not the MUD's. Thank you for that.

The codebase is based on Merc 2.1, based on Rom2.4 copyright 1993 - 1994 Russ Taylor.

It worked on what you said, put the "".
But on the script it doesn't work. How do i make an alias that makes all the three commands?
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #9 on Thu 05 Feb 2015 09:44 AM (UTC)
Message
If the server doesn't complain about the " " enclosure, change your alias to put keywords in quotes so that it doesn't 'confuse' the server with multiple keywords. That's why it's failing the way you set it up initially - the server is looking for a single 'word' for keyword when you restring and it should treat "(stuff stuff stuffy stuff)" as a single 'word' and allow you to use the alias like you're trying to do. If it's still complaining with the " " enclosure, you're going to need to rework the alias to properly fit the expected input pattern which could get very tricky if you've got something that was built with a lot of keywords.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] bio
Date Reply #10 on Thu 05 Feb 2015 10:20 AM (UTC)
Message
Thank you again.
The alias still getting messed up. Can you help me with the rewritten of that?
I'm really stuck, cause it works if you type one command at a time, but i want to automated that, make the three commands on one alias.
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #11 on Thu 05 Feb 2015 11:41 AM (UTC)

Amended on Thu 05 Feb 2015 11:43 AM (UTC) by Meerclar

Message
Be sure expand variables is checked or this is guaranteed to fail spectacularly.

<aliases>
<alias
match="-stringo -(.*?) -(.*?) -(.*?) -(.*?)"
enabled="y"
expand_variables="y"
group="Restring"
regexp="y"
send_to="12"
keep_evaluating="y"
sequence="100"
>
<send>var item;
var newitem;
var short;
var long;

item = "%1";
newitem = "%2";
short = "%3";
long = "%4";

world.execute(string obj @item name @newitem);
world.execute(string obj "@newitem" short @short);
world.execute(string obj "@newitem" long @long);</send>
</alias>
</aliases>


I'm pretty sure I got that right at least. Using execute rather than send should keep the expanding variables functioning properly within the quotes and if not, Nick should spot any mistakes I made fairly easily. This one's a little beyond what I normally do with aliasing and the command syntax for string is definitely complicating things.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] bio
Date Reply #12 on Thu 05 Feb 2015 11:48 AM (UTC)
Message
variable name is not defined. I changed it to item, and then the newitem is not defined also.
I'm doing this in JScript.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Thu 05 Feb 2015 07:52 PM (UTC)

Amended on Thu 05 Feb 2015 07:54 PM (UTC) by Nick Gammon

Message
I got better results with matching on:


^-stringo -(.*?) -(.*?) -(.*?) -(.*?)$


Example alias in Lua:


<aliases>
  <alias
   match="^-stringo -(.*?) -(.*?) -(.*?) -(.*?)$"
   enabled="y"
   expand_variables="y"
   group="Restring"
   regexp="y"
   send_to="12"
   keep_evaluating="y"
   sequence="100"
  >
  <send>
item = "%1";
newitem = "%2";
short = "%3";
long = "%4";

-- debugging
print ("item", item)
print ("newitem", newitem )
print ("short", short)
print ("long", long)

-- Lua uses .. instead of + to concatenate strings

Send("string obj " .. item .. " name " .. newitem);
Send("string obj " .. newitem .. " short " .. short);
Send("string obj " .. newitem .. " long " .. long);

</send>
  </alias>
</aliases>


Test:


-stringo -foo -bar -pedro -hello world


Output:


item foo
newitem bar
short pedro
long hello world

string obj foo name bar
string obj bar short pedro
string obj bar long hello world

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] bio
Date Reply #14 on Thu 05 Feb 2015 08:15 PM (UTC)
Message
Thank you Nick. But what if you insert:

-stringo -foo -bar of strenght -pedro -hello world

item foo
newitem bar of strenght
short pedro
long hello world

string obj foo name bar
string obj bar of strenght short pedro
string obj bar long hello world

The second line is where my problem resides. It can't be bar of strenght, but only bar.
[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.


8,159 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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 FutureQuest]