Aaaaargh!

boardeaux
Posts: 3
Joined: Wed Jan 06, 2010 11:47 pm

Aaaaargh!

Post by boardeaux »

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

colloquialism
Posts: 6
Joined: Thu Jan 07, 2010 2:00 am

Re: Aaaaargh!

Post by colloquialism »

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:

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] == ...
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:

Code: Select all

venoms = {}
venoms.w = "wyg"
venoms.s = ...
and define your approx 40 venoms there. THEN your alias would look something like:

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
With that script, the input "1w" would give: "blowpipe wyg target" or "spit wyg at target"

Thylacine
Posts: 28
Joined: Sun May 10, 2009 5:04 am

Re: Aaaaargh!

Post by Thylacine »

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

boardeaux
Posts: 3
Joined: Wed Jan 06, 2010 11:47 pm

Re: Aaaaargh!

Post by boardeaux »

That did the trick, thanks very much!

One dumb question though, what is the $ for at the end of the alias pattern?

hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: Aaaaargh!

Post by hempa »

In a regular expression, $ means "end of line". If you didn't have it there, the following alias:
^1(\w+)
would match
1somelongtextuntilawhitespace
:)

boardeaux
Posts: 3
Joined: Wed Jan 06, 2010 11:47 pm

Re: Aaaaargh!

Post by boardeaux »

ahhh, I see. Thank you

maharach
Posts: 3
Joined: Sat Feb 26, 2011 4:12 am

Re: Aaaaargh!

Post by maharach »

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

User avatar
Omni
Posts: 131
Joined: Fri Feb 12, 2010 10:26 am

Re: Aaaaargh!

Post by Omni »

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
You're setting the variable venoms to both a function and a table.

maharach
Posts: 3
Joined: Sat Feb 26, 2011 4:12 am

Re: Aaaaargh!

Post by maharach »

ah, so don't put it in a function?

User avatar
Omni
Posts: 131
Joined: Fri Feb 12, 2010 10:26 am

Re: Aaaaargh!

Post by Omni »

maharach wrote:ah, so don't put it in a function?
just change the names for either the function or the table.

Post Reply