Jump to content

simple recycling


Recommended Posts

I am trying to create a relatively simple mod that allows you to insert items with durability such as tools or armor into a science machine and get components back based on the durability they have (each item passing a percent chance to get back check using the percent durability minus a little to make it less overpowered)

this is my first mod, and as i was instructed i looked at various other mods that seem to have similar function as well as base game code, and after several hours i compiled what i thought would be an easy first test, that would simply give back the full recipe cost back from putting anything with durability into the science machine, regaurdless of durability.

unfortunately when i start don't starve and go to the modlist, it says "Crashed!" even before i attempt to enable it! after i attempt to enable it and click apply, it goes unresponsive and i am forced to close it. just looking at the code for a few more hours, i cant think of something that might be wrong with it. 

anything at all would be appreciated.

My Modmain is as follows

local function recycleengine(prefab)
    prefab:AddComponent("trader")
    
    prefab.components.trader:SetAcceptTest(function(prefab, item)
        
        if not item.finiteuses then
            return false
        end
        return true
    end)
    
    prefab.components.trader.onaccept = function(prefab, giver, item)
        if item.components.finiteuses then
                prefab.components.prototyper.onactivate()
                prefab:DoTaskInTime(1.5, function() 
                        prefab.components.lootdropper:SpawnLootPrefab("recipe.ingredients")
                    end
                end)
            end
        end
    end
    
end
AddPrefabPostInit("researchlab", recycleengine)

 

      

Link to comment
Share on other sites

Don't despair, use the log.txt to gain additional information on the crash:

The indent part (that means with empty space to the left) is the "traceback", the line above should say exactly when and why the game crashed.

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