[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Perlscript
. . -> [Subject]  No idea what i'm doing wrong

No idea what i'm doing wrong

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Yasik   Ukraine  (15 posts)  [Biography] bio
Date Thu 01 Nov 2007 07:46 PM (UTC)
Message
Dont laugh too loud :)

I want to make an alias "kk", that does "kick elf" when i
type "kk elf" and does just "kick" when i type "kk".
So i made this:

Alias: ^kk (?P<who>.*?)$
checked Enabled
checked Regular Expression
Send To: World
Label: kick_someone
Script: Kick

The script itself looks like this:

sub Kick {
$kicked = GetAliasWildcard("kick_someone", "who");
if ($kicked eq "") { $world->Send("Kick"); }
else { $world->Send("Kick"." ".$kicked); }
}

It does "Kick elf" when i type "kk elf", but it sends just "kk" to the world when i type "kk" without arguments. I give up. Where's the bug(s), ex&#1089;ept in my DNA? :)

Also wonder how to bind a macros on Alt+W ...
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Thu 01 Nov 2007 08:11 PM (UTC)
Message
There's probably something in the string like a space or something that's preventing it from being equal to "". Or, the string is undefined. You can try:


sub Kick {
  $kicked = GetAliasWildcard("kick_someone", "who");
  if ($kicked == undef or $kicked ~= /^\s*$/) { $world->Send("Kick"); }
  else { $world->Send("Kick"." ".$kicked); }
}


The regular expression is saying: return true if kicked contains only space characters from the beginning to the end. (It might be =~, not ~=; I can never remember that.)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Yasik   Ukraine  (15 posts)  [Biography] bio
Date Reply #2 on Thu 01 Nov 2007 08:37 PM (UTC)

Amended on Thu 01 Nov 2007 08:38 PM (UTC) by Yasik

Message
Both seems not to work for some reason...
In case of "~=" it shows:

Script error
World: Sloth 3
Execution of line 4 column 0
Immediate execution
syntax error at (eval 2) line 3, near "$kicked ~"
syntax error
Error context in script:
1 : sub Kick {
2 : $kicked = GetAliasWildcard("kick_someone", "who");
3 : if ($kicked == undef or $kicked ~= /^\s*$/) { $world->Send("Kick"); }
4*: else { $world->Send("Kick"." ".$kicked); }
5 : }

In case of "=~" it sends "Kick" when i type "kk elf" and "kk" when i type "kk".

I think i'm goin to read some perl manuals or sort...
[Go to top] top

Posted by Onoitsu2   USA  (248 posts)  [Biography] bio
Date Reply #3 on Thu 01 Nov 2007 09:07 PM (UTC)
Message
Some languages use <> for symbolizing not equal to, so you might try that. I myself have not used perl for anything other than a simple assignment in cgi-bin for use on a webpage, and that was several years ago, so it is anyone's guess.

-Onoitsu2
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #4 on Thu 01 Nov 2007 09:19 PM (UTC)
Message
Perl uses != for not-equals, except for strings, where you use ne. (But we're not looking for not-equals here.)

Unfortunately Yasik I don't really know how to go forward from here since it might be a problem with how you're setting up the alias. (I don't really know how to do that.)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 01 Nov 2007 11:55 PM (UTC)
Message
Quote:

I want to make an alias "kk", that does "kick elf" when i
type "kk elf" and does just "kick" when i type "kk".


The simple approach is to not build in the space into the alias. That is:

Match: kk*
Send: kick%1

That way, if you type kk on its own, it still matches (as it isn't looking for a space), and sends "kick", but if you type "kk elf" then %1 is " elf" and it sends "kick elf".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Yasik   Ukraine  (15 posts)  [Biography] bio
Date Reply #6 on Fri 02 Nov 2007 04:44 AM (UTC)
Message
It does work now :) Thanx all! Looks like i was diggin in too deep as for beginner

What about Alt-W macros? Dont want change habits
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Fri 02 Nov 2007 05:12 AM (UTC)

Amended on Fri 02 Nov 2007 05:13 AM (UTC) by Nick Gammon

Message
In Lua, you could do this:

Accelerator ("Alt+W", "some_action_here")

In Perl the syntax will be slightly different, see this page for a description:

http://www.gammon.com.au/scripts/doc.php?function=Accelerator


Accelerators are temporary changes to the world, to make it permanent you need a script to run at world open, and do them in that.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by KP   (24 posts)  [Biography] bio
Date Reply #8 on Sun 04 Nov 2007 08:51 AM (UTC)

Amended on Sun 04 Nov 2007 11:55 PM (UTC) by KP

Message
The problem was not with your original script, but with the trigger regex. The way it was built, it was looking for `kk maybesomething'. Notice the whitespace behind "kk"? Thats why simply "kk" didn't trigger at all and went through directly to the world. If you modify the regex to `^kk(?P<who>.*?)$' (or the simplest way as Nick suggested `^kk(.*?)$'), it would have worked right away, but possibly also catching things it is not supposed to catch (like "kkinfo", which might be some other alias). So a fool-proof version would be `^kk(\s.*)?$', and then send "kick %1" to the world.
[EDIT: fixed my regex, because it still "required" the whitespace to be there. I shouldn't post when tired..]

And Dave's example resulted in a script error, because `~=' is not a valid operator. `=~' is what he meant, which matches a regex on a string.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


28,908 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]