ugh help

Posted by MattMc on Sun 16 Nov 2003 12:06 AM — 5 posts, 34,660 views.

USA #0
Errors:

Global symbol "$linkfile" requires explicit package name at (eval 2) line 4.
Global symbol "$linkfile" requires explicit package name at (eval 2) line 5.
Global symbol "$nlines" requires explicit package name at (eval 2) line 7.
Global symbol "@file" requires explicit package name at (eval 2) line 7.
Global symbol "$returnstring" requires explicit package name at (eval 2) line 8.
Global symbol "$returnstring" requires explicit package name at (eval 2) line 9.
Global symbol "@file" requires explicit package name at (eval 2) line 9.
Global symbol "$nlines" requires explicit package name at (eval 2) line 9.
Global symbol "$returnstring" requires explicit package name at (eval 2) line 10.
Global symbol "$returnstring" requires explicit package name at (eval 2) line 12.
Not enough arguments for send at (eval 2) line 12, at EOF
	(in cleanup) Global symbol "$linkfile" requires explicit package name at (eval 2) line 4.
Global symbol "$linkfile" requires explicit package name at (eval 2) line 5.
Global symbol "$nlines" requires explicit package name at (eval 2) line 7.
Global symbol "@file" requires explicit package name at (eval 2) line 7.
Global symbol "$returnstring" requires explicit package name at (eval 2) line 8.
Global symbol "$returnstring" requires explicit package name at (eval 2) line 9.
Global symbol "@file" requires explicit package name at (eval 2) line 9.
Global symbol "$nlines" requires explicit package name at (eval 2) line 9.
Global symbol "$returnstring" requires explicit package name at (eval 2) line 10.
Global symbol "$returnstring" requires explicit package name at (eval 2) line 12.
Not enough arguments for send 
Line in error: 

Error number: -2147467259
Event: Execution of line 12 column 0
Called by: Immediate execution

Missing script subroutine procedue:
You have not specified a script file name:

The alias subroutine named "Advertise" could not be found.
The timer (RandomAd) subroutine named "Advertise" could not be found.

XML Error:
Line 48: Could not find all required script routines (problem in this file)
-----------Script----------

<?xml version="1.0" encoding="UTF-8"?>

<muclient>
<plugin name="Random_ads"
  author="Matt"
  language="perlscript"
  id = "982581e59ab42844527eec83"
  purpose = "Displays a random ad from time to time"
  save_state = "y"
  version = "1.1"
  requires="3.31"
  >
<description trim="y">
<![CDATA[

]]>            
</description>
</plugin>
 
<!--  =============================================

Script:  DoRandomAd
Purpose: Chooses an advertisement at random from a text file.

 =============================================  -->
 
<timers>
  <timer 
	  name="RandomAd" 
	  script="Advertise" 
	  enabled="y" 
	  second="59"
          minute="1"
	>
  </timer>
</timers>

<aliases>
  <alias
   match="doadnow"
   enabled="y"
script="Advertise" 
  >
  </alias>
</aliases>


<script>
<![CDATA[
use strict;
sub Advertise
{
$linkfile = "C:/ads.txt";
open (LINKS, "$linkfile");
srand();                        
$nlines=@file=<LINKS>;
$returnstring = "emot advertises, '";
$returnstring .= $file[int rand $nlines];
$returnstring .= "'";

world.send $returnstring;

close (LINKS);

}
]]>            
 </script>
 
 </muclient>


I'm very unfamiliar with scripting perl in mushclient, but I'm thinking I did something extremly wrong. Any help would be greatly appreciated.

The ads.txt file contains 1 line faux-ads (only about 20 of them). 1 per line, hard return at the end.
Canada #1
I don't know a thing about Perl, but I know that MUSHclient tries to pass one argument to any subroutine it calls from a timer. (The argument being the Timer Name). Taking a wild guess, it doesn't look like your subroutine accepts arguments.

Hopefully that's one item nailed down...
USA #2
use strict;

There's the source of your problem... if you know VB, that's quite similar to Option Explicit.

In other words, all of your variables need to be defined before you use them.

This is generally a good thing to have. You can remove it, but I wouldn't recommend it.

What you should do is declare all variables using "my".

e.g.

my $linkfile = "C:/ads.txt";


You don't need to do this for the file handle; that's the bareword LINKS.

Whenever you see "global symbol (...) requires explicit package name at (...) line ...", that most likely means that you are running in strict mode, and you didn't declare the variable before referring to it.
Amended on Sun 16 Nov 2003 09:29 AM by David Haley
Australia Forum Administrator #3
Perl accepts arguments differently than VBscript, Magnum, so that part is probably OK.

There are example Perl scripts in the MUSHclient distribution.

Choosing one ad out of 20 sounds like the random socials plugin, you could look at how that does it. In its case it stores the messages in a variable saved in the plugin state file.
USA #4
I figured it out, but couldn't have done it without yalls help :D

Thanks for a wonderful client, Nick.


Joe