Jump to content

[Help]What did I wrong here?


Cyde042

Recommended Posts

 Shortly, a mod that stop food spoiling after being done on a drying rack and in the crock pot. This is what I have.

PrefabFiles = {	"meatrack","cookpot",}function NoSpoil_Rack(inst) 	if inst.components.dryer and inst.components.dryer.spoiltask then	    inst.components.dryer.spoiltask:Cancel()	    inst.components.dryer.spoiltask = nil	    -- inst.components.dryer.spoiltargettime = nil	endendfunction NoSpoil_Pot(inst)	if inst.components.stewer and inst.components.stewer.spoiltask then	    inst.components.stewer.spoiltask:Cancel()	    inst.components.stewer.spoiltask = nil	endendAddPrefabPostInit("meatrack", NoSpoil_Rack)AddPrefabPostInit("cookpot", NoSpoil_Pot)

Can anyone help?

Link to comment
Share on other sites

What did you do wrong here?

 

Maybe you need to set a periodic task?

 

Why would I need a periodic task? I need a set it and forget it approach. What I think I need to do is add custom onload,onsave,ondoncecooking and oncontinuedone.

 

What I'm trying to do now is make the the component(stewer) use a custom local function based on the one present in the cookpot prefab, but the issue is, that function is referencing other local functions leading me eventually into an error.

 

I mean. I want to make inst.components.stewer.ondonecooking = custom_function. But first I need to copy the original function, but that leads into many other missing functions. And it ends with me having to load the cooking.lua script from the modmain, and I have no idea how to do that. I put a copy of it in the scripts folder of the mod, and wrote a require line, and it still gives me an error.

Link to comment
Share on other sites

function NoSpoil_Pot(inst)

if inst.components.stewer then

inst.components.stewer.onspoil = nil

local oldFunc = inst.components.stewer.Harvest

inst.components.stewer.Harvest = function(inst, harvester)

inst.targettime = GetTime() --make it cooked just now

oldFunc(inst, harvester)

end

end

end

Link to comment
Share on other sites

You shouldn't need a require line if you put a copy of the stewer component in your scripts directory. If you upload a copy of your mod, I can try to take a look at the code.

 

http://www.filedropper.com/nostewerspoilage

 

A copy of cooking.lua not stewer. What I want to do is to override "inst.components.stewer.ondonecooking = donecookfn". The current state of the mod (that's uploaded) will result in a crash because of the local functions. Ignore the custom components, those are a backup plan.

Link to comment
Share on other sites

function NoSpoil_Pot(inst)	if inst.components.stewer then		inst.components.stewer.onspoil = nil		local oldFunc = inst.components.stewer.Harvest		inst.components.stewer.Harvest = function(inst, harvester)			inst.targettime = GetTime() --make it cooked just now			oldFunc(inst, harvester)		end	endend

 

Crashes, GetTime isn't defined.

 

Link to comment
Share on other sites

Sure it is not, bacause it's in global space. I was hoping you could fix any little things that I missed. :)

function NoSpoil_Pot(inst)    if inst.components.stewer then        inst.components.stewer.onspoil = nil        local oldFunc = inst.components.stewer.Harvest        inst.components.stewer.Harvest = function(inst, harvester)            inst.targettime = GLOBAL.GetTime() --make it cooked just now            oldFunc(inst, harvester)        end    endend
Link to comment
Share on other sites

 

Sure it is not, bacause it's in global space. I was hoping you could fix any little things that I missed. :-)

function NoSpoil_Pot(inst)    if inst.components.stewer then        inst.components.stewer.onspoil = nil        local oldFunc = inst.components.stewer.Harvest        inst.components.stewer.Harvest = function(inst, harvester)            inst.targettime = GLOBAL.GetTime() --make it cooked just now            oldFunc(inst, harvester)        end    endend

 

  Well, besides the character saying "I can't do that" after harvesting, it works. But when I tried applying the same principle to the Rack, I can't even harvest it, it goes into the animation and then says "I can't do that". This is what I have.

function NoSpoil_Rack(inst)     if inst.components.dryer then        inst.components.dryer.spoiltask = nil        local Function = inst.components.dryer:Harvest        inst.components.dryer:Harvest = function(inst, harvester)            inst.targettime = GLOBAL.GetTime()            Function(inst, harvester)        end    endend
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...