Sign in to follow this  
rosalovesyou

[SOLVED] how to make a character cook faster in a cookpot?

Recommended Posts

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! ❤

Share this post


Link to post
Share on other sites
Ultroman    725

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.

Share this post


Link to post
Share on other sites
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 by rosalovesyou

Share this post


Link to post
Share on other sites
Ultroman    725

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).

Share this post


Link to post
Share on other sites

@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 by rosalovesyou

Share this post


Link to post
Share on other sites
Ultroman    725

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?

Share this post


Link to post
Share on other sites
Ultroman    725

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)

 

Share this post


Link to post
Share on other sites
Ultroman    725

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")

 

Share this post


Link to post
Share on other sites

@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 by rosalovesyou

Share this post


Link to post
Share on other sites
Ultroman    725

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

 

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites
Ultroman    725

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this