Variable question

Posted by Girdy on Mon 15 Apr 2002 10:37 PM — 6 posts, 21,456 views.

#0
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?
Australia Forum Administrator #1
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)); 
 } 
#2
Thank you sir. And you have very nice product here. :)
Australia Forum Administrator #3
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".
#4
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.
Australia Forum Administrator #5
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'