Page 1 of 1

Beginner Scripter, weird function collision

Posted: Tue Mar 23, 2010 12:36 pm
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 ?

Re: Beginner Scripter, weird function collision

Posted: Tue Mar 23, 2010 12:39 pm
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 ? :)

Re: Beginner Scripter, weird function collision

Posted: Tue Mar 23, 2010 2:18 pm
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.

Re: Beginner Scripter, weird function collision

Posted: Tue Mar 23, 2010 5:07 pm
by Aldrec
Oh, I see. Pretty simple when you put it like that, thanks for the quick reply !

Re: Beginner Scripter, weird function collision

Posted: Tue Mar 23, 2010 6:02 pm
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.

Re: Beginner Scripter, weird function collision

Posted: Fri Mar 26, 2010 3:05 pm
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.

Re: Beginner Scripter, weird function collision

Posted: Fri Mar 26, 2010 8:32 pm
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.

Re: Beginner Scripter, weird function collision

Posted: Fri Mar 26, 2010 8:37 pm
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.

Re: Beginner Scripter, weird function collision

Posted: Fri Mar 26, 2010 11:42 pm
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

Re: Beginner Scripter, weird function collision

Posted: Sat Mar 27, 2010 1:38 am
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.