Jump to content

some more questions about AddPrefabPostInit() function


dnjswns951

Recommended Posts

I tried that when the character eats evil petals, health goes up by 1. 

 

and here is my code.... in my modmain.lua file

 

local function oneatingpetals_evilevilpostinit(inst)

 

    inst:AddComponent("edible")

    inst.components.edible.healthvalue = 1

    inst.components.edible.hungervalue = 0

    inst.components.edible.foodtype = "VEGGIE"

 

end

 

AddPrefabPostInit("petals_evil", oneatingpetals_evilevilpostinit)

 

 

it works fine. But in the game, when I open the console screen, it says "components "edible" already exists!"

 

So I am just wondering if this code is OK or is there better way to achieve it.

 

The other way I tried is that I copied the whole petals_evil.lua file and changed code in that file. 

And put that file in my mod(scrips/prefab) folder, and it also worked fine.

 

So which one is better way to to this? Or is there a even better way?

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