OK I know I did something terribly unintelligent to get this error;
Fatal error: Uncaught exception 'Exception' with message 'Sorry, you only have Rock Cone, you need 10!' in /home/arieng/catisserie.net/view/completeq1view.php:48 Stack trace: #0 /home/arieng/catisserie.net/view/completeq1view.php(13): Completeq1View->takeItem('Rock Cone', 10) #1 /home/arieng/catisserie.net/classes/class_frontcontroller.php(100): Completeq1View->index() #2 /home/arieng/catisserie.net/index.php(74): FrontController->render() #3 /home/arieng/catisserie.net/index.php(78): IndexController::main() #4 {main} thrown in /home/arieng/catisserie.net/view/completeq1view.php on line 48
I'm sure this will make you cringe to look at but this is the file thus far;
PHP Code:
<?php
class Completeq1View extends View{
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.
if ($mysidia->user->quest1 = "no") {
$document->add(new Comment("<center>Text Text Text<center>", FALSE));
$this->takeItem("Rock Cone",10);
}
else{
$document->add(new Comment("The man furrows his brows at you, <b>sorry, no reward if you don't have any rock cones.</b>", FALSE));
}
}
public function takeItem($item, $qty){
$mysidia = Registry::get("mysidia");
$owned = $mysidia->db->select("inventory", array("quantity"), "itemname ='{$item}' and owner ='{$mysidia->user->username}'")->fetchColumn();
if ($owned >= $qty){
// If the user owns $qty amount or more...
if ($owned == $qty){
$amount = 100;
$mysidia->user->changecash($amount);
$document->add(new Comment("<center>You return to the scientit's camp and present the head scientist with 10 rock cones.<br>
<b>Wow, thank you! Here are some kibs!</b><br>
You've obtained {$amount} kibs!</center>", FALSE));
// Update that they have done the quest
$mysidia->db->update("users", array("quest1" => "yes"), "username = '{$mysidia->user->username}'");
// If the user has exactly $qty left, delete the whole row.
$mysidia->db->delete("inventory", "itemname='{$item}' and owner='{$mysidia->user->username}'");
$amount = 100;
$mysidia->user->changecash($amount);
$document->add(new Comment("<center>You return to the scientit's camp and present the head scientist with 10 rock cones.<br>
<b>Wow, thank you! Here are some kibs!</b><br>
You've obtained {$amount} kibs!</center>", FALSE));
// Update that they have done the quest
$mysidia->db->update("users", array("quest1" => "yes"), "username = '{$mysidia->user->username}'");
} else {
// Subtract $qty from user's inventory.
$owned_left = $owned - $qty;
$mysidia->db->update("inventory", array("quantity" => $owned_left), "itemname ='{$item}' and owner='{$mysidia->user->username}'");
}
} else {
throw new Exception("Sorry, you only have {$owned} {$item}, you need {$qty}!");
}
}
}
?>
Edit;
OK, may be because I didn't actually define $qty at any point...not really sure how to, though @_@ I know that you can see if a user
owns a certain item, but not sure how to define $qty to check how many of that item they own.