Beginner Scripter, weird function collision

Post Reply
Aldrec
Posts: 3
Joined: Tue Mar 23, 2010 12:27 pm

Beginner Scripter, weird function collision

Post by Aldrec »

I'm a beginner in scripting, and even more-so using the Mudlet scripting language. I've been trying to build a basic combat system, but just as I started I hit a hurdle which has got me baffled.

I've got a script which contains functions for eating various herbs, all of them in this format

Code: Select all

function eat_kelp()
	send("outr 1 kelp")
	send("eat kelp")
end
I then made some aliases to call these functions for manual healing such as:

Code: Select all

Alias name: "Weariness"
pattern: "weari"
code: "eat_kelp()"
But, with kelp as example, when I type anything into mudlet containing the word east, whether it is "say east" or "open door east", it will call the eat_kelp() function instead of sending the command I wrote.

This happens with various other words calling other herb functions. Does anyone have any idea what's going on ?

Aldrec
Posts: 3
Joined: Tue Mar 23, 2010 12:27 pm

Re: Beginner Scripter, weird function collision

Post by Aldrec »

Update:

Is it possible that adding the ^ and $ symbols to the beginning and end of the pattern could have fixed this ? If so, could someone please tell me why ? :)

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Beginner Scripter, weird function collision

Post by Heiko »

Mudlet aliases are defined as regex patterns.
^ = begin of line anchor
$ = end of line anchor

If you define your pattern as "wear" instead of "^wear$" your alias will also be called when you type: "wear brown hat" or "He wears a red hat" i. e. whenever Mudlet finds the substring "wear" in the command you enter, your alias script will be called. That is not what you want in 99,9% of the cases. That's why you should always enclose your alias pattern in ^ and $ unless you know what you are doing. For further reading on regex pattern or Lua in general you should look here: http://forums.mudlet.org/viewtopic.php?f=9&t=641

By the way, Lua is a modern scripting language that is widely used outside of Mudlet also.

Aldrec
Posts: 3
Joined: Tue Mar 23, 2010 12:27 pm

Re: Beginner Scripter, weird function collision

Post by Aldrec »

Oh, I see. Pretty simple when you put it like that, thanks for the quick reply !

User avatar
Alexander Divine
Posts: 65
Joined: Mon Dec 21, 2009 7:01 pm

Re: Beginner Scripter, weird function collision

Post by Alexander Divine »

May I also suggest an improvement to your method?

The eat_kelp() function is fine and dandy, but you could make it a bit more powerful!
Code: [show] | [select all] lua
function eat(herb)
-- Awesome code goes here that checks for balances/timers/etc. so you don't waste plants!
  send("outr 1 " .. herb)
  send("eat " .. herb)
end
You can call that easily by just using "eat("kelp")" in a script, alias, etc.

Kennai
Posts: 9
Joined: Sat Jan 30, 2010 6:11 am

Re: Beginner Scripter, weird function collision

Post by Kennai »

You can make your healing even faster if you eat and then outc. This would require you outcing first when you log on, but it'll be worth the small like 16 gold loss of a death.

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: Beginner Scripter, weird function collision

Post by Jules »

Most likely not. Sending two commands at once will not slow Mudlet down at all, so taking kelp from its container will not have any adverse effects on the speed of the curing.

naftali
Posts: 138
Joined: Wed Jan 20, 2010 8:42 pm

Re: Beginner Scripter, weird function collision

Post by naftali »

won't slow Mudlet down, will slow the server on the other end down a tiny bit. Advantage is if you can't outc (webbed, 2 broken arms, etc) you'll still be able to cure some this way.

User avatar
Alexander Divine
Posts: 65
Joined: Mon Dec 21, 2009 7:01 pm

Re: Beginner Scripter, weird function collision

Post by Alexander Divine »

I think he's referring to curing during aeon and whatnot, but my answer is usually to take a ton of herbs out anyway if I fight an Aeon-user. :P

Kennai
Posts: 9
Joined: Sat Jan 30, 2010 6:11 am

Re: Beginner Scripter, weird function collision

Post by Kennai »

It will. I've had several people try this out on mudlet, and I've noticed it on logs of people who use zmud/cmud. There is a delay between the first and second command you enter into Aetolia. It can anywhere from .05 to like .2 seconds. This can be a lot. It's not a mudlet thing, it's an aetolian thing. This time difference does not seem to occur between the third to fourth command or from there on.

Post Reply