Deadend Posted July 31, 2014 Share Posted July 31, 2014 using the OnCreate parameter of a recipe I hooked to a function where I used getModData() and ran a little test to see if it worked. Basically I have two recipesrecipe recipeOne{ Pot, Result: Kettle, Time: 10.0, OnCreate:recipeOne_OnCreate,}recipe recipeTwo{ Kettle, Result: Pot, Time: 10.0, OnTest:recipeTwo_IsValid,}then my two functions were:function recipeOne_OnCreate(items, result, player) local modData = result:getModData(); local hold = "Yup, that's a kettle"; if modData.holdIt then getPlayer():Say("This isn't suppose to happen"); else getPlayer():Say("Watch me turn this pot into a kettle xD "); modData.holdIt = hold; endendfunction recipeTwo_IsValid(sourceItem, result) local modData = sourceItem:getModData(); local hold = "Well, that didn't work as expected"; if modData.holdIt then getPlayer():Say("... " .. modData.holdIt); else getPlayer():Say("uhmm..."); modData.holdIt = hold; endendAnd so in that little example there (which I made just to fool around and see if getModData() worked as I was expecting it to) my end result was: - I right clicked pot, triggered recipe to turn into kettle, good so far. My player says "Watch me turn this pot into a kettle xD" as expected.- I right clicked kettle, which triggered the function hooked onto the OnTest parameter. my player says "uhmm". A second right click gives "Well, that didn't work as expected" and every right click after that gives the same string. So basically getModData() worked as expected on the second function, I later exit game, logged back in, and I still was getting "Well, that didn't work as expected" from right clicking the kettle. But why didn't it work from the first function to the second? Anybody knows? Well, if anyone could enlighten my path, this would safe me a lot of time. P.S: Someone might say, well the recipe item isn't created yet so you can't set things like that on it. Well then how come I can apply moodlet changes on consumable items? Link to comment Share on other sites More sharing options...
RobertJohnson Posted July 31, 2014 Share Posted July 31, 2014 Try something like modData["holdIt"] = "true" Link to comment Share on other sites More sharing options...
RoboMat Posted July 31, 2014 Share Posted July 31, 2014 Try something like modData["holdIt"] = "true" modData.holdIt and modData["holdIt"] are the same thing in lua Link to comment Share on other sites More sharing options...
RobertJohnson Posted July 31, 2014 Share Posted July 31, 2014 But modData.holdIt won't be save (well, maybe it has changed, but back then they wouldn't be saved...) Link to comment Share on other sites More sharing options...
RoboMat Posted July 31, 2014 Share Posted July 31, 2014 Ah okay didn't know that. It must have changed, since it worked fine with the lockpicking modmodData = door:getModData();modData.lockLevel = modData.lockLevel or 0;@DeadendAre you sure, that the paremeter of the second function is what you think it is? Link to comment Share on other sites More sharing options...
Deadend Posted July 31, 2014 Author Share Posted July 31, 2014 Ah okay didn't know that. It must have changed, since it worked fine with the lockpicking mod modData = door:getModData();modData.lockLevel = modData.lockLevel or 0;@DeadendAre you sure, that the paremeter of the second function is what you think it is? I've used OnTest before, its what used for the flashlight to make sure the battery is drained out in order to allow you to see and essentially trigger the 'Insert' battery recipe. But both battery insertion/removal recipes only deal with one "ingredient" so to speak. When you use the OnTest parameter for a recipe with multiple ingredients (I've ran some tests) it seems to pick the last ingredient item listed in your recipe. I've tried iterating through it but it doesn't work (through that sourceItem parameter) so its not a list. And it's worked on other things I've done before. Like for example I had a recipe that would could only be used if OnTest function returned true (the code checked to make sure your last ingredient was cooked) and it worked exactly as expected. Gonna keep running some tests. And maybe now that you mention it, take a look at the guts of the lockpicking mod. Link to comment Share on other sites More sharing options...
Deadend Posted August 1, 2014 Author Share Posted August 1, 2014 Well, no luck. Guess the result parameter in the first function holds a sort of pre-item copy of whats to be made or something like that (because for some reason it doesn't save, it only seems to save information onto ModData when the item is already in existence). Even tried with the OnMakeItem event to trigger a different function which essentially did the same as function one and no luck. Can't seem to be able to save anything onto the result 'item' ModData. Bummer. Time to re-design my mod to not use ModData.... Link to comment Share on other sites More sharing options...
RoboMat Posted August 1, 2014 Share Posted August 1, 2014 You still can use mod data ... all you need is to change the place where you apply the mod data Link to comment Share on other sites More sharing options...
Deadend Posted August 1, 2014 Author Share Posted August 1, 2014 You still can use mod data ... all you need is to change the place where you apply the mod data yeh, actually just figured a different way go about it by using an item that already exists (applying mod data to it). If it works then that proves my thesis. Then I can continue my mod as planned. *crossing fingers*. ... interesting that you once struggled with getModData() as well and actually learned about it from the same source as I did. http://www.theindiestone.com/community/viewtopic.php%3Ff=38&t=16221.html . I know everyone has to start somewhere but someone like you who has contributed so much to the modding community its hard to imagine you were ever a novice modder . Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now