Item Function Is Invalid
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 Code:
|
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: http://i1290.photobucket.com/albums/...ps2b12a65c.jpg |
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 Code:
|
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 Code:
|
Well its still incorrect, the syntax should be:
PHP Code:
|
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? |
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 |
Clearly you have misspelled the word registry.
|
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... |
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... |
I see, mind posting the actual source code of your item function here?
|
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* |
re
Uh oh, I'm a bummer - can someone show me an example or the location of the source codes? :(
|
Hall Of Famer means the function you made, the whole code from the file
Btw you have the if still liek this? if($gender = 'f') It should be if($gender == 'f') = means you are giving the variable a value. == means you are comparing it (it's a function that says if it is false or true) Btw if you already have the switch-case you can take the if off. Like PHP Code:
|
Re
Oh, it has to be 2 equal signs - I'll try that! Thanks for the tip. :3
Edit: Thanks, you fixed half of my problem! The item says "action completed" and gets deleted, but my male adoptable is still male, and the "gender change successful messge" does not pop up. :L Also, here's the code: PHP Code:
|
I simulated what you wanted to do and it's working, I used only if's instead switch-cases (not to mix if's and switch-cases since they both do the same):
PHP Code:
PHP Code:
Also, the item deletes anyway at the end because it's not inside the the case. You have to delete the item if it succeeds, so it should be inside the case. Also each case must end with break; so it knows when to stop. Since your adopt was male, it was reaching the switch-case (the else). But it would only activate if it was female, so it ignored it and proceeded to item deletion so that's why it was decreasing and not changing the gender. To avoid this kind of confusion, you only delete the item if the switch-case is sucessful. With your own code: PHP Code:
|
I guess my post was a bit misleading, I was merely referring to the source code of the very item function you created, not the source code of the entire functions_items.php file. For this case it is not a problem, but at some circumstances it may be time consuming to read through an entire script file. Id say just post the code that aint working is sufficient when bringing up a problem.
|
Re
Ah. I see! xP
Well, in that case, here's the code! :D PHP Code:
Here's the finished code :D: PHP Code:
|
I already explained why it wasn't working, see the post above Hall Of Famer's. Your switch case is wrong
case "f": .... ^ The switch-case only does the code (update thingy) you have after it if your adopt's gender is female. So it will only change the gender from female to female. You need to change it to case "m". |
Yeah, I edited my last post. Anyways, thank you so much! I probably would have kept changing the code and fixing nothing if you didn't point that out. >^.^<
|
Quote:
|
Sorry to bump up this thread, but I was seeing if I could try out this mod (and then do one similar for color/marking changing) and have been running into the same item function invalid error. I'm using 1.3.4, so I'm not sure if maybe that's the issue or not or if I've run into an error with my itemfunctions table in general (I assume that the intent is for adoptable, but I may have done it wrong) . ^v^;
|
Quote:
In the item_functions table, the function parameter is the name of your item function (in this example, it would be genderf) and in this case the intent is for Adoptable yes. After that, you will have to go to the classes folder and edit the file class_privateitem.php. In the apply() function, inside the big switch-case, you have to put another 'case' to add the new item type |
Yay! Thank you so much! It works wonderfully! Now I'll tinker with it for some breed and color change mods (maybe marking change too)
|
All times are GMT -5. The time now is 10:25 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.