FlawlessHair Posted March 8, 2016 Share Posted March 8, 2016 (edited) Hello. I want to remove the 'inventoryitemmoisture' component from all items. I figure I'd do this by calling InventoryItem:EnableMoisture(false) on all items. However, I have no idea how to get a reference to all items. Is there a way to do that, without having to write every single name down in an array? Edited March 8, 2016 by FlawlessHair Link to comment https://forums.kleientertainment.com/forums/topic/65233-solved-change-component-for-multiple-prefabs/ Share on other sites More sharing options...
Arkathorn Posted March 8, 2016 Share Posted March 8, 2016 --Adds PostInit for all prefabs AddPrefabPostInitAny(function(inst) if inst.components.inventoryitem then inst.components.inventoryitem:EnableMoisture(false) end end Link to comment https://forums.kleientertainment.com/forums/topic/65233-solved-change-component-for-multiple-prefabs/#findComment-731234 Share on other sites More sharing options...
FlawlessHair Posted March 8, 2016 Author Share Posted March 8, 2016 (edited) Thank you Arkathorn! I have no idea where to find the API for Don't Starve, so I would have no way figuring that one out. How did you know about the line 'AddPrefabPostInitAny'? EDIT: Also, the code doesn't seem to work. AddPrefabPostInitAny(function(inst)) --Remove moisture from items if inst.components.inventoryitem then inst.components.inventoryitem:EnableMoisture(false) end --Remove moisture components if inst.components.moisture then inst:RemoveComponent("moisture") end end It gives me the error: 65: Unexpected symbol near ')' Which is where I placed the extra ) since it seemed missing from your script (2 open and only 1 closing). Removing it gives me an error saying it expected ')' to close at 65. Not sure what it wants me to do. EDIT2: Fixed it! Turns out you have to place ')' after the final 'end'. What a weird way to code, but I guess that's how .lua works. Edited March 8, 2016 by FlawlessHair Link to comment https://forums.kleientertainment.com/forums/topic/65233-solved-change-component-for-multiple-prefabs/#findComment-731255 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now