Register forum user name Search FAQ

Gammon Forum

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 ➜ Perlscript ➜ Variable question

Variable question

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


Posted by Girdy   (9 posts)  Bio
Date Mon 15 Apr 2002 10:37 PM (UTC)
Message
I get this error:

Error number: -2146827284
Event: Execution of line 2 column 5
Description: Expected ';'
Called by: Immediate execution

For this function:
(target is defined on the variables menu with a basic default of 'foo'.)


sub OnTargeter
{
my ($thename, $theoutput, $wildcards) = @_;

$world->SetVariable ("target",($thename, 101));

}

And here's the alias:
Alias: tt *
Send:
Label: Targeting
Script OnTargeter

This is the entire script so far, I'm trying to make a basic system to then run off of and creatively change. Do I need to add a #usr/bin/perl statement at the top or is the problem really something else?

Also, if I was to write an alias to use this modification in the script, would it be say kick @target or $target?
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 15 Apr 2002 11:17 PM (UTC)
Message
To get the first wildcard value you need to call "$world->GetAliasInfo" using value 101 (wildcard 1). You have omitted that part.

This will work, I tried it...


sub OnTargeter 
 { 
 my ($thename, $theoutput, $wildcards) = @_; 
 $world->SetVariable ("target", $world->GetAliasInfo ($thename, 101)); 
 } 

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Girdy   (9 posts)  Bio
Date Reply #2 on Tue 16 Apr 2002 (UTC)
Message
Thank you sir. And you have very nice product here. :)
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #3 on Tue 16 Apr 2002 12:07 AM (UTC)
Message
Thank you.

I see I didn't answer your other questions. :)

Quote:

Do I need to add a #usr/bin/perl statement at the top or is the problem really something else?


No you don't need that.

Quote:

Also, if I was to write an alias to use this modification in the script, would it be say kick @target or $target?


You would say "kick @target", and check "Expand Variables".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Girdy   (9 posts)  Bio
Date Reply #4 on Tue 16 Apr 2002 10:01 PM (UTC)
Message
Thanks a ton again. My scripts are running well and good thanks to your help.

Two more questions for you though:

1. I've been using the $world->GetVariable
(i.e $itcombat = $world->GetVariable ("tcombat");) method to get global variables into my subs. Is there another way?

2. Is there a way to just look at the first or second letter in a wildcard (Off a trigger) or in a script? For instance, if I wanted to know that the second letter in 'apple' was a p.

Thanks again, you've been a great help.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #5 on Tue 16 Apr 2002 11:25 PM (UTC)
Message
Quote:

1. I've been using the $world->GetVariable (i.e $itcombat = $world->GetVariable ("tcombat");) method to get global variables into my subs. Is there another way?


No, that is the usual way.

Quote:

2. Is there a way to just look at the first or second letter in a wildcard (Off a trigger) or in a script? For instance, if I wanted to know that the second letter in 'apple' was a p.


In Perl you can use "substr" to do that. You supply the string in question, and an offset (number of characters to skip), and a length. If you omit the length the entire rest of the string is returned. eg.


$result = substr ("apple", 1, 1); # returns 'p'
$result = substr ("apple", 2); # returns 'ple'

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


16,995 views.

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

Go to topic:           Search the forum


[Go to top] top

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