Help Debugging Quest Code

Forum
Last Post
Threads / Messages

Abronsyth

A Headache Embodied
Member
Joined
Aug 25, 2011
Messages
1,012
Points
36
Location
NY
Mysidian Dollar
73,285
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:
    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));
		}
	}
 
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:
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.
 
Last edited:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top