Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts

    Help me spot the bug?

    Have a small bug and can't find it. There are 4 character classes, and the WHILE loop works fine as you can see the items are different.

    But it's displaying Enchantress as the class for all items. The Small Cane should be Enchantress, Fayts Sword should be Knight, and The knife should be Thief.

    The database is correct, I triple checked it. But it's something all in the same class.

    Then in the equip function, it gives me the error that I am not the same character class. Any help?

    INVENTORY
    PHP Code:
      $weaponquery doquery("SELECT * FROM {{table}} WHERE playerid='".$userrow['id']."' AND type='1'"'smithcreate');
        
    $classweapon mysql_fetch_array($weaponquery);
        

            
    $title 'Equipment Inventory';
            
    $page "<table width='100%' border='1'><tr><td class='title'><a href='index.php'>Gameplay</a> > <a href='equipinv.php'>Equipment Inventory</a></td></tr></table>";

            
    $page .= "<table width='100%'><tr><td class='title'><center><h3><font color=white>WEAPONS</font></h3></center></td></tr></table>";
            
    $page .= '<p><table width="95%">';
            
    $page .= '<tr><td><b>Weapon Name</b></td><td><b>Min Level</b></td><td><b>Damage</b></td><td><b>Class</b></td><td><b>Upgrade</b></td><td><b>Action</b></td></tr>';
            if (
    mysql_num_rows($weaponquery) == 0) {
              
    $page .= '</table>';
              
    $page .= '<center><p>You have no weapons in your inventory.</center>';
            }
            else {
            while (
    $wrow mysql_fetch_array($weaponquery)) {

             if (
    $classweapon['class'] == 1) {
          
    $weapon1 'Enchantress';
        }
        elseif (
    $classweapon['class'] == 2) {
          
    $weapon1 'Knight';
        }
        elseif (
    $classweapon['class'] == 4) {
          
    $weapon1 'Archer';
        }
        elseif (
    $classweapon['class'] == 7) {
          
    $weapon1 'Thief';
        }

            if (
    $wrow['equipped'] == 'No') {
              
    $setweapon "<a href='equipinv.php?x=equipweapon:".$wrow['id']."'>EQUIP</a>";
            }
            else {
              
    $setweapon "<a href='equipinv.php?x=unequipweapon:".$wrow['id']."'>REMOVE</a>";
            }

            
    $page .= "<tr><td>".$wrow['name']."</td><td>Lvl ".$wrow['requirement']."</td><td>+".$wrow['attribute']."</td><td>$weapon1</td><td>+".$wrow['bonusattack']."</td><td>$setweapon</td></tr>";
          }
          
    $page .= '</table>'

    EQUIP
    PHP Code:
    function equipweapon($id) {

        global 
    $userrow$numqueries;

        
    $updatequery doquery("UPDATE {{table}} SET location='Equipment Inventory' WHERE id='".$userrow["id"]."' LIMIT 1""users");

        
    $weaponquery doquery("SELECT * FROM {{table}} WHERE playerid='".$userrow['id']."' AND id='$id'"'smithcreate');
        
    $equipw mysql_fetch_array($weaponquery);

        if (
    $equipw['class'] == 1) {
          
    $equipw2 'Enchantress';
        }
        elseif (
    $equipw['class'] == 2) {
          
    $equipw2 'Knight';
        }
        elseif (
    $equipw['class'] == 4) {
          
    $equipw2 'Archer';
        }
        elseif (
    $equipw['class'] == 7) {
          
    $equipw2 'Thief';
        }

        if (
    $equipw2 != $userrow['charclass']) {
          
    display("<p>Your not the same class as this weapon requires.<br /><br /><a href=\"equipinv.php\">Equipment Inventory</a>.""Error");
        }
        
        if (
    $userrow['level'] < $equipw['requirement']) {
          
    display("<p>You aren't a high enough level to equip this weapon.<br /><br /><a href=\"equipinv.php\">Equipment Inventory</a>.""Error");
        }
        
        if ((
    $userrow['weaponid'] != 0) || $userrow['weaponname'] != 'None') {
          
    display("<p>You already have a weapon equipped. Please remove it first.<br /><br /><a href=\"equipinv.php\">Equipment Inventory</a>.""Error");
        }

            
    $title 'Equipment Inventory';
            
    $page "<table width='100%' border='1'><tr><td class='title'><a href='index.php'>Gameplay</a> > <a href='equipinv.php'>Equipment Inventory</a> > Equip Weapon</td></tr></table>";

           
        
    $page .= "You have successfully equipped the <b>".$equipw['name']."</b>."
    Last edited by myfayt; 08-26-2011 at 08:23 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Start by dumping the values you are comparing to reach that logic and work backward from there to see how they got those values.

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Ah ha! tricky little bug. in the IF and ELSEIFs had to change $classweapon to $wrow
    Last edited by myfayt; 08-26-2011 at 08:22 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •