Jump to content

Recommended Posts

Hi, 

 

I'm trying to add a random chance to get an extra carrot when picked this is what I'm using 

 

local function AddNewCarrotDrop(inst)
    local ranNum = math.random(2)
    inst.components.pickable:SetUp("carrot", 10, ranNum)
end
 
AddPrefabPostInit("carrot", AddNewCarrotDrop)
 
It keeps crashing 
 

attempt to index field 'pickable' (a nil value) 

modmain.lua (3,1)

 

 

this is the same thing I'm using for grass and twigs and they work just fine.  Any help would be appreciated 

 

 

Edited by jjdamstra
Link to comment
https://forums.kleientertainment.com/forums/topic/51107-carrot-drop/
Share on other sites

I'll attempt to take a look, however I'm not very good at coding.

 

I might have fixed it, let me test.

local function AddNewCarrotDrop(inst)	local ranNum = math.random(2)	inst.components.pickable:SetUp("carrot", 10, ranNum)endAddPrefabPostInit("carrot_planted", AddNewCarrotDrop)

There is the fixed code, the issue is if you look in carrot.lua it returns the prefab as carrot_planted.

 

Enjoy! I am actually glad I could help :D

Edited by bigpak

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
×
  • Create New...