Lou Hernsen <mailto:[EMAIL PROTECTED]> wrote:

: I am trying to create a module that will print the Stats of the
: player of my on line game.
: all it should do is take the vars, do some calulations and print the
: HTML 
: since the Stats is used in every time i don't want to duplicate it in
: each program.

    So there is just one subroutine.


: The main program has all your players vars loaded...
: the Stats subroutine (which I want to make into a mod)
: puts the HTML code in the <BODY> of the web page...
: from what I have read this should not be a hard things to do.

    No. It is pretty easy.


: Module= a piece of code that is repeated in several programs.

    That's what I thought you were after, but I wanted to be sure.


: Each location in the town is a separate program....
: If I can't get this to work I'll just leave the sub Stats()  in
: each program and not worry about it.

    Many people use copy and paste to reuse code. The problem is
you may need to make a change. Either you have to write a program
to make the changes in every file or you resign to not making the
change. A module is definitely the right solution for you.

package Stats;

# No need for BEGIN. Read the Exporter docs for details.
use Exporter 'import';

# Any element of this array will be imported into
# calling package namespace (probably main::).
@EXPORT = qw(Speed);

sub Speed
{
 $v0 = 1+$Army+$Hero+$Spy;
 $v1 = 1+$Army+$Hero+$Spy+$Wagon;
 if  ($Wagon < 1 && $Horse >= $v0
  && $Saddle >= $v0 && $Blanket >= $v0
  && $Load <= 100)
    {$Speed = "1.5";}
 elsif ($Wagon == 0 && $Horse >= $v0 && $Load <= 100)
    {$Speed = "2";}
 elsif ($Wagon > 0 && $Horse >= $v1 && $Load <= 100)
  {$Speed = "2.5";}
 elsif ($Wagon == 0 && $Load <= 100)
  {$Speed = "3";}
 elsif ($Load > 100)
  {$Speed = (int(.3 * $Load))/10;}
 else {$Speed=3;}

 # Do your HTML stuff
}

# This is more common than using "return 1;"
1;

    In your program do this.

use lib '.';        # Point to the directory where you placed
                    # your module.

#use Stats;         # This is fine, but
use Stats 'Speed';  # this tells you where Speed() come from.

        .
        .
        .

Speed();



HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328

PS  Please, please, please, don't use global scoped variables in your
    subroutines. Lou is stubborn, but the rest of you are not off the
    hook. Pass all variables into the your subs and pass all variables
    out of your subs. Do not operate (or depend) on variables which
    are external a subroutine.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to