Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
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: 136,947
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
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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

Currently Active Users: 3163 (0 members and 3163 guests)
Threads: 4,081, Posts: 32,032, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636