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!
help! need simple alias which includes numbers
-
- Posts: 6
- Joined: Tue Jun 07, 2011 11:55 pm
Re: help! need simple alias which includes numbers
^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.
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.
Re: help! need simple alias which includes numbers
alias pattern is:
^ga ?(\d+)?$
code is
or "ga 10" would "get 10 apple from tree" .
^ga ?(\d+)?$
code is
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" .
-
- Posts: 6
- Joined: Tue Jun 07, 2011 11:55 pm
Re: help! need simple alias which includes numbers
cool stuff! thanks delrayne and demonnic!
-
- Posts: 6
- Joined: Tue Jun 07, 2011 11:55 pm
Re: help! need simple alias which includes numbers
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!
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!
Re: help! need simple alias which includes numbers
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])))
^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])))
-
- Posts: 6
- Joined: Tue Jun 07, 2011 11:55 pm
Re: help! need simple alias which includes numbers
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.
-
- Posts: 6
- Joined: Tue Jun 07, 2011 11:55 pm
Re: help! need simple alias which includes numbers
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?
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?
-
- Posts: 6
- Joined: Tue Jun 07, 2011 11:55 pm
Re: help! need simple alias which includes numbers
pure awesomeness!