blazerdrive09 Posted June 27, 2016 Share Posted June 27, 2016 So I have successfully added my config settings to the modinfo file and it appears in don't starve together. However, I need the data to be sent to the prefab file of the item I am adding in the mod and I did not know how to go about doing that. I decided to do this based on what I've seen other mods do as this would cause the instance of the item being created to call upon the config data and then add the tag i need onto the instance of the item. local function ComposterPost(inst) if GetModConfigData("WHATTODECAYINTO") == 1 then inst:AddTag("guano") else if GetModConfigData("WHATTODECAYINTO") == 2 then inst:AddTag("rot") end end end AddPrefabPostInit("compost_box", ComposterPost) However, for some reason, the tag is not being added to the instance of the composter and as a result all stuff inside the composter decays into rot. here is the code in the perishable lua file: if owner:HasTag("composter") and self.inst.prefab ~= "bird_egg" and owner:HasTag("guano") then goop:Remove() goop = SpawnPrefab("guano") end this works normally but with the addition of the owner:HasTag("guano") it doesnt work anymore and I am assuming its due to the fact that the inst:AddTag("guano") is not running though default is set to guano and I made sure it was set to guano through the config settings for the mod in game before i went to go test it. As a result, I was wondering if there is a way to pass the config data to the prefab file so it can add the tag guano or rot to the instance of the composter or is there a way to get this the fucntion ComposterPost to correctly attach to the prefab of compost_box like I intend it to do in this case or what is it exactly that is going on that is causing this to fail? Link to comment Share on other sites More sharing options...
Mobbstar Posted June 27, 2016 Share Posted June 27, 2016 Are you sure the configdata is numbers and not strings? Also make sure you used the right name for the configdata. Link to comment Share on other sites More sharing options...
blazerdrive09 Posted June 27, 2016 Author Share Posted June 27, 2016 I am sure my configdata is numbers i double checked it as well as made sure the I'm using the right name, literally copied and pasted into the code above to make sure I didn't misspell anything. Link to comment Share on other sites More sharing options...
CarlZalph Posted June 27, 2016 Share Posted June 27, 2016 45 minutes ago, blazerdrive09 said: I am sure my configdata is numbers i double checked it as well as made sure the I'm using the right name, literally copied and pasted into the code above to make sure I didn't misspell anything. Should post the modinfo.lua and any usage of it in modmain.lua instead of the tidbits. We'll generally assume fault on the programmer than anything under the hood related without seeing the code. Also slight optimization is that you'd have two different addprefabpostinits and only call one of them with the get config data, so you're not continually getting the config data for each prefab construct. Link to comment Share on other sites More sharing options...
blazerdrive09 Posted June 27, 2016 Author Share Posted June 27, 2016 Makes sense, I would do the same just thought the issue was due to something in the code i posted. Anyway here ya go: Modinfo.lua: name = "A composter" description = "Let the fertalizer roll in!" author = "Blazerdrive09 and Jd5team" version = "1.0" forumthread = "" api_version = 6 dst_compatible = true dont_starve_compatible = false reign_of_giants_compatible = false all_clients_require_mod = true icon_atlas = "composter.xml" icon = "composter.tex" configuration_options = { { name = "WHATTODECAYINTO", label = "Decays Into", hover = "Whether food in the composter turns into guano or rot", options = { {description = "Guano", data = 1}, {description = "Rot", data = 2}, }, default = 1, } } modmain.lua: PrefabFiles = { "compost_box" } Assets = { Asset( "IMAGE", "minimap/composter.tex" ), Asset( "ATLAS", "minimap/composter.xml" ), Asset("IMAGE", "images/inventoryimages/composter.tex"), Asset("ATLAS", "images/inventoryimages/composter.xml"), } AddMinimapAtlas("minimap/composter.xml") local require = GLOBAL.require local Vector3 = GLOBAL.Vector3 local TUNING = GLOBAL.TUNING local IsServer = GLOBAL.TheNet:GetIsServer() local TheInput = GLOBAL.TheInput local ThePlayer = GLOBAL.ThePlayer local net_entity = GLOBAL.net_entity STRINGS = GLOBAL.STRINGS RECIPETABS = GLOBAL.RECIPETABS Recipe = GLOBAL.Recipe Ingredient = GLOBAL.Ingredient TECH = GLOBAL.TECH local decaysinto = GetModConfigData("WHATTODECAYINTO") GLOBAL.STRINGS.NAMES.COMPOSTER = "Composter" STRINGS.RECIPE_DESC.COMPOSTER = "Get that Fertalizer!" GLOBAL.STRINGS.CHARACTERS.GENERIC.DESCRIBE.COMPOSTER = "It smells" local composter = GLOBAL.Recipe("composter",{ Ingredient("cutgrass", 6), Ingredient("poop", 2), Ingredient("log", 2) }, RECIPETABS.FARM, TECH.SCIENCE_ONE, "composter_placer" ) composter.atlas = "images/inventoryimages/composter.xml" local function ComposterPost(inst) if GetModConfigData("WHATTODECAYINTO") == 1 then inst:AddTag("guano") else if GetModConfigData("WHATTODECAYINTO") == 2 then inst:AddTag("rot") end end end AddPrefabPostInit("compost_box", ComposterPost) compost_box.lua require "prefabutil" local assets= { Asset("ANIM", "anim/composter.zip"), Asset("ANIM", "anim/ui_chest_3x3.zip"), } local prefabs = { "collapse_small", } local function onopen(inst) inst.SoundEmitter:PlaySound("dontstarve/wilson/chest_open") inst.AnimState:PlayAnimation("open") end local function onclose(inst) inst.AnimState:PlayAnimation("close") inst.SoundEmitter:PlaySound("dontstarve/wilson/chest_close") end local function onhammered(inst, worker) inst.components.lootdropper:DropLoot() inst.components.container:DropEverything() local fx = SpawnPrefab("collapse_small") fx.Transform:SetPosition(inst.Transform:GetWorldPosition()) fx:SetMaterial("wood") inst:Remove() end local function onhit(inst, worker) inst.AnimState:PlayAnimation("hit") inst.components.container:DropEverything() inst.AnimState:PushAnimation("close", false) inst.components.container:Close() end local function onbuilt(inst) inst.AnimState:PlayAnimation("place") inst.AnimState:PushAnimation("idle") end local function itemtest(inst, item, slot) return (item.components.edible and item.components.perishable) or item.prefab == "spoiled_food" or item.prefab == "rottenegg" or item.prefab == "guano" end local function onsave(inst, data) if inst:HasTag("burnt") or (inst.components.burnable ~= nil and inst.components.burnable:IsBurning()) then data.burnt = true end end local function onload(inst, data) if data ~= nil and data.burnt and inst.components.burnable then inst.components.burnable.onburnt(inst) end end local function fn(Sim) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddNetwork() local minimap = inst.entity:AddMiniMapEntity() minimap:SetIcon( "composter.tex" ) MakeObstaclePhysics(inst, .7) inst:AddTag("composter") inst:AddTag("structure") inst.AnimState:SetBank("composter") inst.AnimState:SetBuild("composter") inst.AnimState:PlayAnimation("idle", true) MakeSnowCoveredPristine(inst) inst.entity:SetPristine() if not TheWorld.ismastersim then inst.OnEntityReplicated = function(inst) inst.replica.container:WidgetSetup("compost_box") end return inst end inst:AddComponent("inspectable") inst:AddComponent("container") inst.components.container:WidgetSetup("compost_box") inst.components.container.onopenfn = onopen inst.components.container.onclosefn = onclose inst:AddComponent("lootdropper") inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(1) inst.components.workable:SetOnFinishCallback(onhammered) inst.components.workable:SetOnWorkCallback(onhit) AddHauntableDropItemOrWork(inst) MakeSnowCovered(inst) inst.OnSave = onsave inst.OnLoad = onload return inst end return Prefab( "common/composter", fn, assets), MakePlacer("common/composter_placer", "composter", "composter", "idle") Link to comment Share on other sites More sharing options...
blazerdrive09 Posted June 29, 2016 Author Share Posted June 29, 2016 Any insight anyone? Link to comment Share on other sites More sharing options...
Recommended Posts
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.