[ Please use <p> at the start of every paragraph, and please use <c>...</c> tags around computer text (code, data, output, etc). Your post is barely readable. ]
Actually, that will make him lose 0-19hp. You need int(rand(21)) to generate an integer in 0-20.
sub reduce_hp {
my ($hp) = @_;
$hp -= int(rand(21));
return $hp;
}
my $char_hp = 400;
$char_hp = reduce_hp($char_hp);
print("Character now has $char_hp hp\n");
or maybe
sub reduce_hp {
my ($hp) = @_;
$hp -= int(rand(21));
$_[0] = $hp;
}
my $char_hp = 400;
reduce_hp($char_hp);
print("Character now has $char_hp hp\n");
It's a rather useless function, though. It simply shifted code without adding value.
|