Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Plugins
➜ Getting the right argument at the right place
Getting the right argument at the right place
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Martijn
(20 posts) Bio
|
Date
| Sat 26 May 2007 06:54 PM (UTC) |
Message
| I am having some trouble getting the right part of the matched text send to a script. What I am trying now is the following:
<alias
script="target_tester"
match="^target (\w+)"
enabled="y"
ignore_case="y"
regexp="y"
>
</alias>
with this script (in perlscript)
sub setTarget{
my $i = 0;
for my $arg (@_){
$world->note("arg ".$i." is ".$arg);
$i++;
}
}
when I put in "target bigbadwolf" I expected the following to come out:
arg 0 is target bigbadwolf
arg 1 is bigbadwolf
what comes out is:
arg 0 is
arg 1 is target bigbadwolf
arg 2 is ARRAY(0xf8ed9c)
what I want is to get that argument bigbadwolf, but I can't seem to get it. I'm probably doing it completely wrong, and I would really appreciate a hand.
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 26 May 2007 10:41 PM (UTC) |
Message
| Take a look at the examples in exampscript.pl file that comes with MUSHclient.
For example, getting a wildcard for an alias:
sub OnAddTeleport
{
my ($thename, $theoutput, $wildcards) = @_;
# wildcard 2 is the room name
$sDestination = $world->trim ($world->GetAliasInfo ($thename, 102));
...
I think I had trouble accessing wildcards from the array that is passed down to the function, so I made an extra way of getting at them, namely:
http://www.gammon.com.au/scripts/doc.php?function=GetAliasInfo
You can now also use:
http://www.gammon.com.au/scripts/doc.php?function=GetAliasWildcard
So, the simple answer is, assuming you have a name for your alias (in the Label field) then all you would have to do is call GetAliasWildcard, using that name, and the wildcard number you want. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Martijn
(20 posts) Bio
|
Date
| Reply #2 on Sun 27 May 2007 11:07 AM (UTC) |
Message
| Once again, Nick Gammon to the rescue! So from what I gather, the array of wildcards is not send to the script, but is instead stored in an internal datastructure, and I can get them out again one by one and get them in a new array with (for perlscript again)
<alias
script="argument_tester"
match="^(match) (the) (big) (bad) (wolf)"
enabled="y"
ignore_case="y"
regexp="y"
name="argument_tester"
></alias>
sub argument_eater{
my $name = shift;
my $output = shift;
my $wildcards = shift;
my @arguments = ();
for (my $i = 0; push (@arguments GetAliasWildcard ($name, $i);$i++;){}
}
for my $argument (@arguments){
$world->note("argument is ".$argument);
}
}
For now this will more than suffice for me. The only difficulty I might still run in to, is that this only works if argument_eater would be called from an alias. If it is called from a Trigger it won't work, as I would need GetTriggerWildcard. If I would call it from another script method, it would pass the array as an argument. I could make a seperate function for that one, i.e. have a trigger_argument_eater an alias_argument_eater and a sub_argument_eater. Do you know of any workarounds? It would be especialy nice if I could access the built in array, if I could name the array in the trigger/alias and pass the arrays name to the function, or even access the internal array just by its memory adress (I assume the ARRAY(0xf8ed9c) is the memory adress of the internal array), but I could also imagine you have some sort of built in function, (I couldn't find it, but I think I proved my skills in finding the proper function are lacking somewhat) that determines the caller of the script, and if it is an Alias or a Trigger.
Anyway, thank you again for the response, in by far the most cases, I'll be able to do exactly what I want now. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 27 May 2007 09:02 PM (UTC) |
Message
| There is a GetTriggerWildcard function, as I gather you noticed.
This seems to be a limitation of Perl, or my knowledge of it anyway.
The array is indeed passed to your script function ($wildcards in my example), however I had trouble accessing it, as it is internally a VBscript Variant Array type.
In most languages (eg. VBscript, JScript, Lua) I had no trouble accessing the wildcard directly from the array supplied as the third argument.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Martijn
(20 posts) Bio
|
Date
| Reply #4 on Sun 27 May 2007 10:08 PM (UTC) |
Message
| with my limited knowledge of OLE/COM objects I thought activePERL would magicaly poof it and make everything allright. It seems not. Even my targetting system, which was working properly before has gone dodgy now. I have it now as
<aliases>
<alias
script="setTarget"
match="^target (\w+)"
enabled="y"
ignore_case="y"
regexp="y"
name="targetting"
></alias>
</aliases>
<script>
<![CDATA[
sub setTarget{
my ($theName, $theOutput, $wildcards) = @_;
my $target = GetAliasWildcard($theName, "1");
$world->note("setting target to ".$target);
$world->setVariable("target",$target);
my $fetchedTarget = $world.getVariable("target");
$world->note("target is now ".$fetchedTarget);
}
]]>
as it is now, imputting should output
setting target to bigbadwolf
target is now bigbadwolf
right?
wrong. It gives
setting target to bigbadwolf
target is now Win32::OLE=HASH(0xfaa1b4)bigbadwolf
I'm confused now...
| Top |
|
Posted by
| Martijn
(20 posts) Bio
|
Date
| Reply #5 on Sun 27 May 2007 10:26 PM (UTC) |
Message
| quick note to keep the spirits up: note how 0xfaa1b4 is almost hex: Fail b4.
Okay, that was a little lame. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #6 on Mon 28 May 2007 01:50 AM (UTC) |
Message
| Yes, it failed before. :)
Quote:
setting target to bigbadwolf
target is now Win32::OLE=HASH(0xfaa1b4)bigbadwolf
Ah, Perl. :P
Maybe this will work:
$world->setVariable("target", "$target");
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Martijn
(20 posts) Bio
|
Date
| Reply #7 on Mon 28 May 2007 10:15 AM (UTC) |
Message
| Alas. I'm going to have to learn VB, Jscript or Lua I guess... Or might it do any good to drop a crosspost in the Perlscript section? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #8 on Mon 28 May 2007 08:43 PM (UTC) |
Message
| Could be worth a try. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Martijn
(20 posts) Bio
|
Date
| Reply #9 on Mon 28 May 2007 11:14 PM (UTC) |
Message
| Fortunately, I haven't scripted that much yet, and switching to Python for now have given my no such dificulties yet. I'll still put down a crosspost, and see if there are any fixes or workarounds. | 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.
25,408 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top