I am trying to get a random number and assign it to a variable (may seem stupid, but I'm still having trouble.) The code I'm having a problem with:
do{
$goblin=$goblin-$damage;
if($goblin<0){
$goblin=0;
}if($wizard<0){
$wizard=0;
}
if($room==6){
my $dmg=int (rand 5)+1;
}elsif($room==3){
my $dmg=int (rand 4)+1;
}elsif($room==2){
my $dmg=int (rand 3)+1;
}elsif($room==1){
my $dmg=int (rand 2)+1;
}
$wizard-=$dmg;
print "wizard health: $wizard\t";
print "$monster health: $goblin\n";
}until($goblin<=0 || $wizard<=0);
if($wizard>0){
print "good job you got $newgold gold!\n";
$gold+=$newgold;
&freedale;
}elsif($wizard<=0){
¨
}
}else{
print "Please enter 1, 2, or q...\n";
&battle;
}
I'm trying to get a random value for $dmg (depending on the room you're in) and then subtract that from $wizard. Unfortunately, every time i run the program, $wizard doesn't change (originally 50.) If someone could offer some advice as to what I'm doing wrong, I would appreciate it.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.