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 ➜ Make alias

Make alias

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


Pages: 1  2 

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #15 on Thu 05 Feb 2015 08:19 PM (UTC)
Message
That still leaves an issue if he wants to do something like

-stringo -foo -chocolate bar -pedro -hello world

Passing string obj chocolate bar short pedro is going to cause the command to fail because the syntax will be 'wrong' despite the info being accurate. Is there a simple way to put the newitem info into quotes when its passed? I'm thoroughly out of my area of expertise on that issue.


Actually, it just occurred to me that I've been trying to do that the hard way. Halig, forget about trying to put quotes around the newitem variable when it's passed to the server, put quotes around your keywords if you're going to use multiple keywords. The quotes will get passed as part of the variable and the server should treat the entire thing as 1 'word' for command syntax purposes.

ie -stringo -foo -"chocolate bar" -pedro -hello world

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #16 on Thu 05 Feb 2015 08:43 PM (UTC)
Message
It parses that OK:


item foo
newitem chocolate bar
short pedro
long hello world

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


The hyphens delimit the different word groups. You could conceivably add the quotes in the alias, eg.


<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";

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

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

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




Test:


-stringo -foo -chocolate bar -pedro -hello world


Output:


item foo
newitem chocolate bar
short pedro
long hello world

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

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #17 on Thu 05 Feb 2015 08:45 PM (UTC)
Message
Probably a better regexp would be this:


^-stringo -([^-]+?) -([^-]+?) -([^-]+?) -([^-]+?)$


That's because '*' matches anything, including hyphens. Also you want "one or more" not "zero or more" in the brackets.

This variation matches "one or more" of "anything except hyphen" which is what you really want.

- Nick Gammon

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

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #18 on Thu 05 Feb 2015 08:56 PM (UTC)
Message
Now it works. Thank you all.
There is only one problem. When you put that, the name on the nweitem appears with the "chocolate bar".
Is there any way to take off the ""?
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #19 on Thu 05 Feb 2015 10:23 PM (UTC)
Message
Got an example of that so I can be sure what you're talking about?

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #20 on Thu 05 Feb 2015 10:28 PM (UTC)
Message
item book
newitem book of pedro
short book of pedro
long Here lies the book of pedro.
string obj "book" name "book of pedro"
string obj "book of pedro" short "book of pedro"
string obj "book of pedro" long "Here lies the book of pedro."

If then you look at your inventory, the item book of pedro, has the "booke of pedro", meaning that the item got the name with the "".
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #21 on Thu 05 Feb 2015 10:53 PM (UTC)
Message
Only place you should need quotes around your stuff is multi-word newitem. Nothing else needs them for the alias to function properly.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #22 on Fri 06 Feb 2015 11:47 AM (UTC)
Message
Still nothing.
I guess i just have to make three aliases to make those things. If i have the three separated, everything is good.
Thank you for trying to help.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #23 on Fri 06 Feb 2015 08:53 PM (UTC)
Message
Please post exactly what you are typing, exactly what your alias is, and exactly what gets sent.

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.

- Nick Gammon

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

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #24 on Thu 12 Feb 2015 08:32 PM (UTC)
Message
Hello again.

Nick, let's try this diferently.
Tell me something, if i have a variable that countains let's say, book of pedro.
How can i use that variable but get only the first word?
That's all i need, to collect from the variable the first word.
Thank you.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #25 on Thu 12 Feb 2015 08:49 PM (UTC)
Message

test = "book of pedro"

firstWord = string.match (test, "^(%a+)")

print (firstWord)



Prints:


book


Template:regexp Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.

- Nick Gammon

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

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #26 on Fri 13 Feb 2015 10:31 AM (UTC)
Message
Hello again Nick,
Thank you for your patience, but how ca i do that using Jscript?
I have more scripts assigned to aliases and if i change the script of MushClient to lua, the other ones don't work.
Thank you again.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #27 on Fri 13 Feb 2015 07:37 PM (UTC)
Message
I recommend you use Lua. If you don't want to, put the other aliases into a plugin. Plugins each have their own script language, so some plugins can use Jscript and others Lua.

There must be a way of find a single word in Jscript, I suggest Google.

- Nick Gammon

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

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #28 on Fri 13 Feb 2015 07:50 PM (UTC)
Message
Thank you Nick. I didn't knew that you could turn all the other aliases and triggers into a plugin using diferent languages. Thank you. All is working now.
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.


72,964 views.

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

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.