Page 1 of 1

Can't seem to find my issue...

Posted: Wed Aug 01, 2012 2:16 am
by Xaos

Code: Select all

<?php

$diceroll=rand(1,170);
$yardage=20;

if ($diceroll >=1){
  $commentary= "The Quarterback drops back......Pressure from the backside........ SACK ! Big hit by the defensive end.....wait ! There's a fumble.....recovered by the linebacker ! Touchdown Defense!";
  $playgain=-100;
  $yardage=($yardage+$playgain);
}
if ($diceroll >=10){
$commentary= "Yes.";
$yardage=($yardage+$playgain);
$playgain=5;
}
if ($diceroll >=20){
 $commentary= "No.";
 $yardage=($yardage+$playgain);
     $playgain=10;
}
if ($diceroll >=30){
 $commentary= "Maybe";
$yardage=($yardage+$playgain);
     $playgain=15;
}
if($diceroll >=40){
$commentary= "You're an ig+no+ra+moose!!";
$yardage=($yardage+$playgain);
     $playgain=20;
}
if ($diceroll >=50){
 $commentary= "lol did you seriously just ask that?";
$yardage=($yardage+$playgain);
     $playgain=25;
}
if ($diceroll >=60){
$commentary= "umad?";
$yardage=($yardage+$playgain);
        $playgain=30;
}
if ($diceroll >=70){
 $commentary="Oh heck naw!";
  $yardage=($yardage+$playgain);
               $playgain=35;
}
if ($diceroll >=80){
  $commentary= "LOL@UR SWAG";
 $yardage=($yardage+$playgain);
        $playgain=40;
}
if($diceroll >=90) {

  $commentary= "Ask your mother.";
 $yardage=($yardage+$playgain);
      $playgain=45;
}
if ($diceroll >=100){

  $commentary= "You'll know when you're older.";
$yardage= ($yardage+$playgain);
      $playgain=50;
}
if ($diceroll >=110){
  $commentary= "Most Definetly!";
 $yardage=($yardage+$playgain);
             $playgain=55;
  }
  if ($diceroll >=120){
    $commentary= "Oh Yeaaaaaaah!";
    $yardage=($yardage+$playgain);
             $playgain=60;
    }
    if ($diceroll >=130){
      $commentary= "This is factual.";
      $yardage=($yardage+$playgain);
              $playgain=65;
      }
      if ($diceroll >=140){
        $commentary= "Google it.";
        $yardage=($yardage+$playgain);
          $playgain=70;
        }
        if ($diceroll >=150){
          $commentary= "After pondering your inquest most thoroughly I have come to the conclusion that one most certainly could paricpate int the question of your concern";
          $yardage=($yardage+$playgain);

            $playgain=75;
          }
          if ($diceroll >=160){
            $commentary= "Fo Shizzle My Nizzle.";
            $yardage=($yardage+$playgain);
               $playgain=80;
            }
            if ($diceroll >=170){
              $commentary= "You betcha.";
              $yardage=($yardage+$playgain);
                      $playgain=85;
              }

               echo "$commentary<br>";
                echo "$yardage<br>";
                echo "$diceroll<br>";
                echo "$playgain<br>";


              ?>
When I do it, everything works correctly, but I get huge numbers for Yardage that doesn't make any sense to me, such as -40 for a diceroll of 88, or 95 for a diceroll of 111. Also, ignore the "commentary".....that's not the real commentary of which will be in the game, this is all imported code using the same system as a Magic 8 Ball app i'm currently using on my site.

Re: Can't seem to find my issue...

Posted: Wed Aug 01, 2012 2:33 am
by Callan S.
What's at -40?

Re: Can't seem to find my issue...

Posted: Wed Aug 01, 2012 2:42 am
by Xaos
Callan S. wrote:What's -40?
The yardage when I roll, examples:

(first number is yardage, second is dice-roll)

You'll know when you're older.
45
102

Google it.
275
142

LOL@UR SWAG
-40
83

Fo Shizzle My Nizzle.
420
166

The only one that works is the first one.

Re: Can't seem to find my issue...

Posted: Wed Aug 01, 2012 3:49 am
by Callan S.
See the $playgain=-100;?

Code: Select all

    if ($diceroll >=1){
      $commentary= "The Quarterback drops back......Pressure from the backside........ SACK ! Big hit by the defensive end.....wait ! There's a fumble.....recovered by the linebacker ! Touchdown Defense!";
      $playgain=-100;
      $yardage=($yardage+$playgain);
    }

Code: Select all

    if ($diceroll >=80){
      $commentary= "LOL@UR SWAG";
     $yardage=($yardage+$playgain);
            $playgain=40;
    }
Possibly '$yardage=($yardage+$playgain);' should be after the $playgain modification. Otherwise sometimes playgain is -100, it makes $yardage take that into account, then it makes $playgain=40;

Getting closer to the prob?

Re: Can't seem to find my issue...

Posted: Wed Aug 01, 2012 3:57 am
by Xaos
Callan S. wrote:Well, you do have $playgain set here to =-100. And any roll at all is going to make it have -100.

Code: Select all

    if ($diceroll >=1){
      $commentary= "The Quarterback drops back......Pressure from the backside........ SACK ! Big hit by the defensive end.....wait ! There's a fumble.....recovered by the linebacker ! Touchdown Defense!";
      $playgain=-100;
      $yardage=($yardage+$playgain);
    }
I have it echoing the playgain for each one, and everytime, it says the right number I have in the code, but the yardage doesn't reflect that. IE:


Yardage 475
Diceroll 148
Playgain 70

I can even set the first number to 0, but it still creates absurd numbers. Another example

Yardage 20
Diceroll 10
Playgain 5

As we see here, it isn't added AT ALL. So confused.


Alas, it doesn't change a thing.

Re: Can't seem to find my issue...

Posted: Wed Aug 01, 2012 4:12 am
by Xaos
Okay, I have found the source of the problem. It is adding up all of the "yardgains" then adding it to the yardage. Any idea how I can fix this? :(

Re: Can't seem to find my issue...

Posted: Wed Aug 01, 2012 4:27 am
by Callan S.
I'll just check the effect you want

Code: Select all

if ($diceroll >=20){
 $commentary= "No.";
 $yardage=($yardage+$playgain);
     $playgain=10;
}
if ($diceroll >=30){
 $commentary= "Maybe";
$yardage=($yardage+$playgain);
     $playgain=15;
You know that if $diceroll=33, for example, BOTH the first and second if statement will occur?

If you only want one if statement to occur, you'd need something like

Code: Select all

if ($diceroll >=20 && $diceroll<30){
 $commentary= "No.";
 $yardage=($yardage+$playgain);
     $playgain=10;
}
if ($diceroll >=30 && $diceroll<40){
 $commentary= "Maybe";
$yardage=($yardage+$playgain);
     $playgain=15;
As well as doing that to all your other if statements.

Re: Can't seem to find my issue...

Posted: Wed Aug 01, 2012 4:44 am
by Xaos
Gah ! Of Course ! Now I feel dumb, lol. I just imported the dice rolls and such from the magic 8 ball like I had said, and because that was dealing with just text, I didn't have those kind of issues. Thanks for your help !

Re: Can't seem to find my issue...

Posted: Wed Aug 01, 2012 5:42 am
by Jackolantern
You could also change each IF to an IF/ELSE IF so that only 1 can be completed for each roll. You also need to put the most exceptional result at the top. In this case, that means the highest first, then the next highest, and on down. Like Callen said, when you have >=1 at the top, that will always get called for any roll when 1 is the lowest that can be rolled. You need to have the 170 check first, then 160, 150, etc. And just to be safe, make them all IF/ELSE IF structure :)

Re: Can't seem to find my issue...

Posted: Thu Aug 02, 2012 1:09 am
by Xaos
Jackolantern wrote:You could also change each IF to an IF/ELSE IF so that only 1 can be completed for each roll. You also need to put the most exceptional result at the top. In this case, that means the highest first, then the next highest, and on down. Like Callen said, when you have >=1 at the top, that will always get called for any roll when 1 is the lowest that can be rolled. You need to have the 170 check first, then 160, 150, etc. And just to be safe, make them all IF/ELSE IF structure :)
Thanks alot mate, I did'nt even think about that !