Yeah, I figured, that's what an echo does. You'll have to decide what you want to actually be doing as a result. It all depends on what you actually wanted to be doing with the function...?
I would suggest this:
PHP Code:
$takeItem = $this->takeItem("Rock Cone", 10);
if ($takeItem){
$document->add(new Comment("Thank you for bringing me those Rock Cones!", FALSE));
} else {
$document->add(new Comment("Hey, this isn't enough Rock Cones!", FALSE));
}
but you'll need to have the function return a true or false value (I've added one or the other here to all possible outcomes):
PHP Code:
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){
// If the user has exactly $qty left, delete the whole row.
$mysidia->db->delete("inventory", "itemname='{$item}' and owner='{$mysidia->user->username}'");
return true;
} 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}'");
return true;
}
} else {
return false;
}
}
I would NOT modify the function above as you did - if you want to reward the user with something, you should do it in the first half of this post after the success/fail message. That way the code is reusable regardless of the reward.