Right, just discovered Mudlet this week and its awesome. Thank you people/person who did make it.
But I really suck at programming and I can't get me head round something. I'm trying to create an alias thing to allow my character to spit or blowpipe a poison based on typing 1something. The something would be a pre-defined variable. The spit or blowpipe would happen based on whether the character was in or out of the forest - based on another variable called inforest.
So typing 1w would - spit wyg at target or blowpipe wyg target. There is a list of approx 40 poisons that would have to be pre-defined as variables.
So far I have the following but it doesn't work:
Alias name: Target1
Pattern: ^tt(\s(\w+))
Script:
target=(matches[3])
send("tt " .. target)
Alias name: Pipe/Spit
Pattern: ^1(\w+)
Script:
w=wyg
if inforest==1 then
send("blowpipe " .. matches[2] .. " " .. target)
else
send("spit " .. matches[2] .. " at " .. target)
end
A trigger sets whether inforest or not. This part and the target part seems to works ok.
Not sure how to get the pattern match to translate to the variable value. The output seems to just be spit w at target or blowpipe w target
Aaaaargh!
-
- Posts: 6
- Joined: Thu Jan 07, 2010 2:00 am
Re: Aaaaargh!
There are two (relatively) simple ways of going about this.
The long, laborious way, is writing out something to test against what you match, e.g:
and so on and so forth. Unless you're masochistic, I don't recommend this. The faster way to get what you want done is to use a table. If you have an alias that you run at login to initialize variables and tables, you'd want to add:
and define your approx 40 venoms there. THEN your alias would look something like:
With that script, the input "1w" would give: "blowpipe wyg target" or "spit wyg at target"
The long, laborious way, is writing out something to test against what you match, e.g:
Code: Select all
if matches[2] == "w" then
if inforest==1 then
send("blowpipe " .. matches[2] .. " " .. target)
else
send("spit " .. matches[2] .. " at " .. target)
end
elseif matches[2] == ...
Code: Select all
venoms = {}
venoms.w = "wyg"
venoms.s = ...
Code: Select all
Pattern: ^1(\w+)$
Script:
if inforest==1 then
send("blowpipe " .. venoms[matches[2]] .. " " .. target)
else
send("spit " .. venoms[matches[2]] .. " at " .. target)
end
Re: Aaaaargh!
You will also want to check if matches[2] is actually in the table, for example:
Code: Select all
Pattern: ^1(\w+)$
Script:
if venoms[matches[2]] != nil then
if inforest==1 then
send("blowpipe " .. venoms[matches[2]] .. " " .. target)
else
send("spit " .. venoms[matches[2]] .. " at " .. target)
end
end
Re: Aaaaargh!
That did the trick, thanks very much!
One dumb question though, what is the $ for at the end of the alias pattern?
One dumb question though, what is the $ for at the end of the alias pattern?
Re: Aaaaargh!
In a regular expression, $ means "end of line". If you didn't have it there, the following alias:
^1(\w+)
would match
1somelongtextuntilawhitespace
^1(\w+)
would match
1somelongtextuntilawhitespace
Re: Aaaaargh!
i don't seem to understand how to initialize tables at login, i'm trying to add a function to my init() script -
function venoms()
venoms = {}
venoms.w = "wyg"
venoms.s = ...
end
and it doesn't seem to be doing anything. and for the alias i'm using this version -
send("outpouch " ..venoms[matches[2]])
if balance.forests==1 then
send("blowpipe " .. venoms[matches[2]] .. " " .. target)
else
send("spit " .. venoms[matches[2]] .. " at " .. target)
end
i'm assuming this isn't the way to go, heh
function venoms()
venoms = {}
venoms.w = "wyg"
venoms.s = ...
end
and it doesn't seem to be doing anything. and for the alias i'm using this version -
send("outpouch " ..venoms[matches[2]])
if balance.forests==1 then
send("blowpipe " .. venoms[matches[2]] .. " " .. target)
else
send("spit " .. venoms[matches[2]] .. " at " .. target)
end
i'm assuming this isn't the way to go, heh
Re: Aaaaargh!
You're setting the variable venoms to both a function and a table.maharach wrote:i don't seem to understand how to initialize tables at login, i'm trying to add a function to my init() script -
function venoms()
venoms = {}
venoms.w = "wyg"
venoms.s = ...
end
and it doesn't seem to be doing anything. and for the alias i'm using this version -
send("outpouch " ..venoms[matches[2]])
if balance.forests==1 then
send("blowpipe " .. venoms[matches[2]] .. " " .. target)
else
send("spit " .. venoms[matches[2]] .. " at " .. target)
end
i'm assuming this isn't the way to go, heh
Re: Aaaaargh!
ah, so don't put it in a function?
Re: Aaaaargh!
just change the names for either the function or the table.maharach wrote:ah, so don't put it in a function?