Item Function Is Invalid

Forum
Last Post
Threads / Messages

Hwona

Member
Member
Joined
Mar 1, 2013
Messages
620
Points
0
Mysidian Dollar
31,589
Hello, I was thinking about trying to make a new item function, but whenever I try to use an item, it says the item function is invalid. Can someone help or point me in the right direction? :3

Yes, I created a new row in adopts_items_functions.

Here's the code:
PHP:
function items_genderf($item, $adopt){
        $mysidia = Registery:: get("mysidia");
        //Let's check if the adoptable is already female.
        $gender = $mysidia -> db -> select ("gender") -> fetchObject();
        if($gender = "f") {
            //The adoptable is already female
            $note = "Your adoptable is already female.";
        }
        else{
            //The adoptable is male. It's gender can be switched to female.
            switch($adopt->gender){
                case "f":
                    $mysidia -> db -> update("owned_adoptables", array("gender" => 'f'),"aid='{$adopt->aid}' and owner ='{$item->owner}'");
                    $note = "Your adoptable {$adopt->name} is now female.";
            }
            //Update item quantity...
            $delitem = $item->remove();
        }
        return $note;
        }

It's suppossed to plug into the existing functions_items script, so I didn't include the php tags.
 
Last edited:
Are you sure the function name matches the naming convention? Take a screenshot from PHPMyadmin and I will see how to help you.
 
Re

Thanks - taking pic... I thought it would be more like an issue with the code.

Edit here it is :3:

 
Last edited:
Well there is indeed an error in your code. This line clearly is not doing the right thing, you aint using the database class properly.

PHP:
$gender = $mysidia -> db -> select ("gender") -> fetchObject();
 
Re

Ah thanks! Now if only I knew exactly how to fix it...

From the looks of it, I think I might have to add something like: ... ownedadopt ->... and so on..
But then, another half of me thinks it's suppossed to be something like getgender. :L

Do you mind telling me what I need to tweak.

PHP:
$gender = $mysidia -> db -> ownedadoptable -> select ("gender") -> fetchObject();

Any closer to getting it right?
 
Last edited:
Well its still incorrect, the syntax should be:

PHP:
$gender = $mysidia -> db -> select ("owned_adoptables", array("gender"), "aid='{$adopt->aid}' and owner ='{$item->owner}'") -> fetchColumn();

Use fetchColumn() if you only want the gender info, but if you wish to pull a collection of information such as type, name, owner and other things out, you can use fetchObject().
 
Re

:D thank you so much! So you have to put all that aid stuff there? :3

o_O but it still says the function is invalid. Is there any other problem with the code?
 
Last edited:
Yeah there is still one more trick you need to apply at least with Mys v1.3.3. Go to the script file class_privateitem.php, find the long switch statement that defines each item function, add yours in the list, and it should be working. In Mys v1.3.4 that will be released in about a week or two, I will make it possible to get the item function name dynamically so you wont have to go through this pain.
 
:D Thanks!
- Oh, now it says that the registery doesn't exist. o_O
 
Last edited:
x.x Poop... I'm suppossed to know how to spell registry... that's embarassing.

Edit: ok, it's working-ish. Unfortunately, it keeps saying my adopt is already female when it's male. o_O What did I do this time...
 
Last edited:
Yeah, I think I messed up again - it keeps displaying the "Your adopt is already female" message regardless of gender....
 
Do an output of the $gender variable to see what it's in there (if you do echo $gender it will appear at the top left of the screen, or make your variable $note equal to $gender). If $gender actually is "f" then the mistake is at the expression, if $gender is not "f" you know you are fetching gender in a wrong way. Sorry, I don't really know the syntax, but this is a simple way of searching where the mistake is
 
Um, the gender might be "female" instead of "f"

Ok, I've tried swapping "f" with "female", but it's still not working... maybe I should try flipping the if and else?
 
Yeah give it a shot, it never hurt to try. XD Anyway if you are talking about an issue with your own code it can be confusing to other people who do not get a complete picture of what you are trying to accomplish.
 
Re

*smacks forehead*
Now I feel dumb - I haven't even told anyone what I'm trying to do...
technically, I'm trying to make an item class that will change your adopt's gender to female. :3
 
I see, in this case the gender is indeed 'f' instead of 'female', but it may not be the problem. Make sure you have an adoptable object that is actually in the item function you create. Use var_dump() on $adopt to see whether it does exist, if it exists the problem may be with your update query.
 
Re

So I just stick it in the functions_items code? :3
Note: I basically did the same thing as all the other function codes... but I can't figure out what's wrong...
 
Last edited:
Re

o_O source code? Uh oh... I made a big mess up - again.
*searches through files in hopes of finding an example of a source code*
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,280
Messages
33,132
Members
1,603
Latest member
Monako
BETA

Latest Threads

Top