help! need simple alias which includes numbers

doubl3mint
Posts: 6
Joined: Tue Jun 07, 2011 11:55 pm

help! need simple alias which includes numbers

Post by doubl3mint »

hey guys, sorry i'm quite new to computer languages, read the manual but didnt find much on what i want to achieve.

basically, i need an alias that allows input of varying numbers

for example, if i wanted to send a command like this to the mud

ga -> get X apple from tree, how should i write the alias?

X could be a number from 1 to 10, and if it is 1, i dont want to have to put 1, but instead the alias should just get apple from tree

thanks in advance!

Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Re: help! need simple alias which includes numbers

Post by Delrayne »

^getapple (\d+)$ as the alias

if (matches[2]) then
send("get " .. matches[2] .. " apple)
else
send("get apple")
end

^^^Put that in your code box.

I might be wrong on the 'if' statement. Not sure whether or not if matches[2] has a value it'll equal true. I'm sure someone else more knowledgeable than I could answer that though. Either way, its a rough comparison to start with.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: help! need simple alias which includes numbers

Post by demonnic »

alias pattern is:

^ga ?(\d+)?$

code is
Code: [show] | [select all] lua
if matches[2] then
  send(string.format("get %s apple from tree", matches[2]))
else
  send("get apple from tree")
end
Using this should do "get apple from tree" if you just type in "ga" and hit enter (minus the "")
or "ga 10" would "get 10 apple from tree" .

doubl3mint
Posts: 6
Joined: Tue Jun 07, 2011 11:55 pm

Re: help! need simple alias which includes numbers

Post by doubl3mint »

cool stuff! thanks delrayne and demonnic!

doubl3mint
Posts: 6
Joined: Tue Jun 07, 2011 11:55 pm

Re: help! need simple alias which includes numbers

Post by doubl3mint »

hi! so i'm back to mudding after a year, and trying to include more aliases! however, i'm facing a problem with the information above.

i create a simple alias for searching, where

^g ?(\w+)?$

if matches[2] then
send(string.format("search %s", matches[2]))
else
send("search")
end

its functions as it should, but when i type "go", it fires off "search o". this was not what i wanted to do, i actually wanted to send "go" to the mud. any ideas? tia!

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: help! need simple alias which includes numbers

Post by demonnic »

yes, in this case you may want to use a pattern like:

^g( \w+)?$

as long as an extra space in the command won't throw it off, you can stop there. If the extra space is a problem, you can use

send(string.format("search %s", string.trim(matches[2])))

doubl3mint
Posts: 6
Joined: Tue Jun 07, 2011 11:55 pm

Re: help! need simple alias which includes numbers

Post by doubl3mint »

my saviour arrives, yet again! thanks demonnic, it works! much appreciated :)
Last edited by doubl3mint on Fri Oct 19, 2012 5:37 pm, edited 1 time in total.

doubl3mint
Posts: 6
Joined: Tue Jun 07, 2011 11:55 pm

Re: help! need simple alias which includes numbers

Post by doubl3mint »

woops, got another question here, was trying to figure out the mudlet manual but what they provided didnt quite work. i want to create another alias, that has two arguments. so it needs to match twice.

what i would like to achieve is to take ____ from ____

so i would type "t apple bag", and mudlet would send "take apple from bag" to the mud. any clues for this one?

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: help! need simple alias which includes numbers

Post by demonnic »

^t (\w+) (\w+)$

code is
Code: [show] | [select all] lua
send(string.format("take %s from %s", matches[2], matches[3]))

doubl3mint
Posts: 6
Joined: Tue Jun 07, 2011 11:55 pm

Re: help! need simple alias which includes numbers

Post by doubl3mint »

pure awesomeness! :)

Post Reply