Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Help Debugging Quest Code (http://www.mysidiaadoptables.com/forum/showthread.php?t=5112)

Abronsyth 04-16-2016 11:58 AM

Help Debugging Quest Code
 
Hello!

Below is a chunk of my quest code. It is supposed to remove 10 rock cones if the user has 10 and has not already completed the quest. If they have completed the quest it is supposed to simply tell them they no longer need rock cones. However, my users have reported that even when they've already done it they are still losing rock cones out of their inventory (and not receiving a reward for it). Does anyone see an issue in this chunk of code that would result in them having 10 rock cones taken out even after already doing it?
PHP Code:

    public function index(){ 
        
$mysidia Registry::get("mysidia"); 
        
$document $this->document
        
$document->setTitle("Turn in 10 Rock Cones");

            
// Allow user to complete quest if they have not yet. 
        
$notdone $mysidia->db->select("users", array("quest1"), "quest1='no' and username='{$mysidia->user->username}'")->fetchColumn();            
        
$takeItem $this->takeItem("Rock Cone"10);

        if (
$notdone){
            if (
$takeItem){
                
$mysidia->db->update("users", array("quest1" => "yes"), "username = '{$mysidia->user->username}'");
                
$amount 150;
                
$mysidia->user->changecash($amount); 
                
$document->add(new Comment("Thank you for bringing me those Rock Cones!<br>
                You've recieve 
$amount kibs as a thankyou!"FALSE));
                
            } else {
                
$document->add(new Comment("Hey, this isn't enough Rock Cones!"FALSE));
            } 
        }
        else {
            
$document->add(new Comment("Sorry, we don't need anymore rock cones."FALSE));
        }
    } 


Kyttias 04-16-2016 03:23 PM

Well, does $notdone hold the boolean value for true/false or a string with the words either "true" or "false" in it? There's a big difference. Try being more explicit with the value you're looking to fill.

PHP Code:

if ($notdone == "true"){ /* ... */ } else { /* ... */ 

Otherwise it'll just look to see if the variable holds any contents at all. Of course it does, so it runs the first statement. A string with the word "false" in it is still a variable with contents in it so it's always going to return a boolean of true. Variables pulled from the database are not explicitly boolean by default. You could always try storing values as 0 or 1 and they would register better, or, change the column type in the database.


All times are GMT -5. The time now is 10:39 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.