View Single Post
  #6  
Old 02-27-2016, 05:52 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 127,490
Kyttias is on a distinguished road
Default

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.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 02-27-2016 at 05:54 PM.
Reply With Quote