rosalovesyou Posted July 4, 2019 Share Posted July 4, 2019 about a month ago i had been working on a mod and looked around for a code of some sorts for what i want to achieve: making my character cook faster than average. i successfully found one, and it was working perfectly at the time! now it doesn't seem to be working and i'm very confused as to why. local old_cook_fn = ACTIONS.COOK.fn ACTIONS.COOK.fn = function(act, ...) local result = old_cook_fn(act,...) local stewer = act.target.components.stewer if result and stewer ~= nil and act.doer:HasTag("mycharacterprefab") then local fn = stewer.task.fn local t = GetTaskRemaining(stewer.task) stewer.task:Cancel() stewer.task = stewer.inst:DoTaskInTime(t*.5, fn, stewer) end return result end this is the code in question. this is all i've tried, to no avail: - adding it to character.lua by itself - adding it to character.lua inside of local master_postinit = function(inst) - adding it to modmain.lua at the very bottom could anyone explain to me what i'm doing wrong, and maybe give some pointers as to what i can do to fix this? ;; thank you very much in advance! ❤ Link to comment Share on other sites More sharing options...
Ultroman Posted July 5, 2019 Share Posted July 5, 2019 Weird that it just stopped working. No errors in the client/server logs? Does your character have the tag "mycharacterprefab"? I would probably come up with a more unique tag than that. That name is very generic, and one I use as a placeholder every time I give people example-code. You can try debugging it using some print-statements to see which parts of the code is actually being run, e.g., you can see if it uses your new COOK.fn and also whether it enters your if-statement. See the newcomer post under the section "Debugging" for more info. Link to comment Share on other sites More sharing options...
rosalovesyou Posted July 5, 2019 Author Share Posted July 5, 2019 (edited) 10 hours ago, Ultroman said: Weird that it just stopped working. No errors in the client/server logs? Does your character have the tag "mycharacterprefab"? I would probably come up with a more unique tag than that. That name is very generic, and one I use as a placeholder every time I give people example-code. You can try debugging it using some print-statements to see which parts of the code is actually being run, e.g., you can see if it uses your new COOK.fn and also whether it enters your if-statement. See the newcomer post under the section "Debugging" for more info. oh yes, i had it changed to my actual character prefab! i just put in "mycharacterprefab" when i showed it here in the forums for better understanding. ;w; since you say it should be working, and i hadn't gotten any errors, i'm gonna test it out one more time. maybe i just didn't notice a difference? i'm not sure how, i even made the .5 to a .1 in order to see a clear difference, but still nothing notable. //shruggie i'll definitely be debugging if i still don't notice anything! tysm for your reply!! <3 oh! for clarity, where should i be adding this? the character.lua or the modmain.lua, and where exactly in the file? just to be sure i'm doing the right thing! Edited July 5, 2019 by rosalovesyou Link to comment Share on other sites More sharing options...
Ultroman Posted July 5, 2019 Share Posted July 5, 2019 I believe that particular code should be at the bottom of modmain (well, under any variable or function declarations used in the snippet, at least). It's a good idea to ensure that you can see the change happening, by making it painfully obvious (your .5 to .1). With some print-statements you should be able to see what parts of the code are executed, by printing recognizable strings, and looking for them in your logs after playing for a bit. Remember that it sometimes won't write to the logs until some times has passed in the game, so I always make sure to at least wait until one clock-segment has been passed (the clock pulses when it happens). Link to comment Share on other sites More sharing options...
rosalovesyou Posted July 5, 2019 Author Share Posted July 5, 2019 (edited) @Ultroman i believe when i wasn't getting errors, i could have been putting it in my character.lua file. because, now that it's at the bottom of modmain.lua, i'm definitely getting an error! i tested my mod before adding this in and it was working perfectly fine, so this code is definitely doing something fishy. i attached my client_log below, since it crashed upon resuming! i can sorta make sense of this but i'm sure you'd know much better what's going on! thank you so much for your speedy reply, too! take your time in figuring this out with me though, no rush! <3 client_log.txt Edited July 5, 2019 by rosalovesyou Link to comment Share on other sites More sharing options...
Ultroman Posted July 5, 2019 Share Posted July 5, 2019 Well, when your code breaks, at least you know it's being executed xD I don't know why, but when I click the client_log.txt file you've linked, it says that the attachment does not exist. Can you post it again? Link to comment Share on other sites More sharing options...
rosalovesyou Posted July 5, 2019 Author Share Posted July 5, 2019 @Ultroman oh i think i know why that happened - i modified my message a few times, and i think i overwrote it by testing other things. XD oops! here you go! hope it works this time! <3 client_log - Copy.txt Link to comment Share on other sites More sharing options...
Ultroman Posted July 5, 2019 Share Posted July 5, 2019 Well, something happens on line 73 of your modmain.lua where you're doing something with ACTIONS. I would need you code to help you further. Attach a zip of your mod to a reply. [00:06:06]: [string "../mods/character-flora/modmain.lua"]:73: attempt to index global 'ACTIONS' (a nil value) Link to comment Share on other sites More sharing options...
rosalovesyou Posted July 5, 2019 Author Share Posted July 5, 2019 @Ultroman i'm pretty sure line 73 is where i put this code, too. here you go! ;w; character-flora.zip Link to comment Share on other sites More sharing options...
Ultroman Posted July 6, 2019 Share Posted July 6, 2019 Add this somewhere above line 73: local ACTIONS = GLOBAL.ACTIONS Link to comment Share on other sites More sharing options...
rosalovesyou Posted July 6, 2019 Author Share Posted July 6, 2019 @Ultroman it's not crashing anymore! though i'm still not noticing a difference? that's odd. Link to comment Share on other sites More sharing options...
Ultroman Posted July 6, 2019 Share Posted July 6, 2019 It has to do with the tag check. You haven't given your character the tag. I would not use your character name as the tag, since it's not quite unique enough. Change the check to: if result and stewer ~= nil and act.doer:HasTag("floraflowergirl") then and then add this to your character.lua's common_postinit function: inst:AddTag("floraflowergirl") Link to comment Share on other sites More sharing options...
rosalovesyou Posted July 6, 2019 Author Share Posted July 6, 2019 (edited) @Ultroman alright, i did just that! however i'm encountering a new error - client_log attached! this error is happening when i hit "cook" on the crockpot. thank you SO much for having so much patience with this and being such a huge help ;w; i wouldn't be this far without you! client_log - Copy (3).txt Edited July 6, 2019 by rosalovesyou Link to comment Share on other sites More sharing options...
Ultroman Posted July 6, 2019 Share Posted July 6, 2019 Alright. Small lesson. Whenever it says something like this: [00:01:56]: [string "../mods/character-flora - Copy/modmain.lua"]:80: attempt to call global 'GetTaskRemaining' (a nil value) The "attempt to call global" means it's trying to call a function in the global scope. Essentially, this means whenever you try to call a function, without specifying a target to call it on, e.g., inst is the target in the following case: inst.GetTaskRemaining(bla, bla) So, if you just call: GetTaskRemaining(bla, bla) ...and there are no local functions with that name, it will try to look for it in the global scope. If it doesn't find it, you get this error. Now, GetTaskRemaining IS in the global scope, but the code in modmain.lua is NOT executed in the game's global scope, so you need to help it along. This is where GLOBAL comes along. GLOBAL is a variable holding a reference to the global game scope, which is made available for modmain.lua. So whenever you see this kind of error, and you're calling a function with no target (no target.TheFunction() or target:TheFunction()), then try putting "GLOBAL." in front of the function-call. You will see a similar, but not identical, error if you try to access a global variable, e.g., TUNING or STRINGS, which is why you are creating references to them at the top and in the middle of your particular modmain.lua (usually you'd group them together at the top for overview and clarity). So, find the line, and replace this part of the line: GetTaskRemaining with this: GLOBAL.GetTaskRemaining Link to comment Share on other sites More sharing options...
rosalovesyou Posted July 6, 2019 Author Share Posted July 6, 2019 @Ultroman OH MY GOD IT'S WORKING thank you SO SO SO MUCH!! i get it!! thank you so much for the lesson too! ah gosh you're such a huge help!! <3 //hugs Link to comment Share on other sites More sharing options...
Ultroman Posted July 6, 2019 Share Posted July 6, 2019 You're very welcome You're paying me back with gratitude. That's my fuel, for some reason ^^ Link to comment Share on other sites More sharing options...
rosalovesyou Posted July 6, 2019 Author Share Posted July 6, 2019 @Ultroman i'm also paying you back with a big special thanks in the mod's description when i upload this to the workshop!! that won't be for a long while for personal reasons, but i'm sure you'll see it someday! <3 Link to comment Share on other sites More sharing options...
Ultroman Posted July 6, 2019 Share Posted July 6, 2019 You are very kind You don't have to do that, but I guess you know that already If you feel like it, please include my full nick, since people seem to have started copying my short-hand (Ultroman). The full nick is Ultroman the Tacoman, which is stupid and hilarious to me, and also my nick on Steam and everywhere that will accept that many letters xD Link to comment Share on other sites More sharing options...
rosalovesyou Posted July 7, 2019 Author Share Posted July 7, 2019 @Ultroman i'll definitely be sure to do that! <3 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