Lumina Posted February 5, 2017 Share Posted February 5, 2017 Hi again. My adventure with container continues. Thanks to people here i managed to make a container. Now i would like to filter items going in this container. Since i would like to have only wood i tried this : function params.log_shelter.itemtestfn(container, item, slot) -- if item.components.edible.foodtype == FOODTYPE.WOOD then -- return true -- end if item:HasTag("edible_FOODTYPE.WOOD") then return true end return false end (The commented function was my first try) but it's not working. How could i achieve that ? I would like to at least accept log, but if possible, all type of "wood" items (log, boards, living log) would be great. Thanks for any help Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/ Share on other sites More sharing options...
alainmcd Posted February 5, 2017 Share Posted February 5, 2017 Does your first idea work with GLOBAL.FOODTYPE.WOOD ? Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864105 Share on other sites More sharing options...
Lumina Posted February 5, 2017 Author Share Posted February 5, 2017 (edited) With or without global i have a "attempt to index field 'edible' (a nil value)", so the problem seems to be with the "item.components.edible.foodtype", but i don't know why it's nil. Should i test first if the item have the component ? Edit : it's strange, some objects works without mistake (like log (could put it in) and charcoal (can't put it in)) and some make the game crash (here it was a juicy berry bush) so i guess it's crashing when the item have no edible component ?... Edited February 5, 2017 by Lumina Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864116 Share on other sites More sharing options...
alainmcd Posted February 5, 2017 Share Posted February 5, 2017 Yes, you should definitely test for the edible component. Not all items have it. if item.components.edible and item.components.edible.foodtype == GLOBAL.FOODTYPE.WOOD then return true end Assuming item will never be nil, or you'll want to test it too. Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864120 Share on other sites More sharing options...
Lumina Posted February 5, 2017 Author Share Posted February 5, 2017 So i changed this part to : if item.components.edible and item.components.edible.foodtype == GLOBAL.FOODTYPE.WOOD then return true end And it seems to work fine now. Thanks a lot for your help ! Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864121 Share on other sites More sharing options...
Lumina Posted February 5, 2017 Author Share Posted February 5, 2017 Is there a case when item could be nil ? I took the icebox test as example and i don't see a test like this : function params.icebox.itemtestfn(container, item, slot) if item:HasTag("icebox_valid") then return true end --Perishable if not (item:HasTag("fresh") or item:HasTag("stale") or item:HasTag("spoiled")) then return false end --Edible for k, v in pairs(FOODTYPE) do if item:HasTag("edible_"..v) then return true end end return false end So i don't see in which case trying to put item in a container could result in a nil item ? (Just curious, not really need help here ) Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864124 Share on other sites More sharing options...
alainmcd Posted February 5, 2017 Share Posted February 5, 2017 Even if you managed to force a case where there was no item, would it make sense? The function is called itemtestfn, after all. No, I just meant that it's a good idea to test anything and everything that can break. There are other cases where you do want to test if the prefab exists. Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864127 Share on other sites More sharing options...
Lumina Posted February 6, 2017 Author Share Posted February 6, 2017 I have a strange problem i don't really understand. If i am the host (server without cave), i could put items in the container in a classic way without problem (putting them in slot or using the "fast" shortcut). If i am not the host, i cannot do this. The only way to put item in the container is to click on the container itself and it will add the item in the slots, but i cannot directly add items in the slots i want. The code i use is based on the icebox code, so i don't see why icebox is working fine and why my code isn't. If anyone have a clue ? I remember the Waiter mod got a similar issue (at least close), with ingredients you couldn't put in crockpot, but the issue was probably different (ingredient side rather than crockpot side i guess). Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864244 Share on other sites More sharing options...
alainmcd Posted February 6, 2017 Share Posted February 6, 2017 I don't know about the Waiter mod, but Large Chest seems to be working fine. The large icebox is basically a clone of the original icebox, look at the modmain.lua, specifically lines 28 to 95. Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864268 Share on other sites More sharing options...
Lumina Posted February 6, 2017 Author Share Posted February 6, 2017 I will do that, thanks a lot again. I'm grateful for the time you spent helping me Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864273 Share on other sites More sharing options...
Lumina Posted February 6, 2017 Author Share Posted February 6, 2017 (edited) After look and test, the only difference i can see, since the icebox code works fine, is that my custom code itself, even is fine, could be problematic, maybe because it use component (seems to be the case since usually, if it works fine at host but not in cave/dedi, it's because of components). I'll maybe try a workaround adding tag to the items i want being able to add to the container. for k, v in pairs(FOODTYPE) do if item:HasTag("edible_"..v) then return true end end But this part of the code seems to "transform" a foodtype (which is linked to component) in a kind of tag. I don't understand how it works, but could be a way to achieve it... Edited February 6, 2017 by Lumina Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864296 Share on other sites More sharing options...
alainmcd Posted February 6, 2017 Share Posted February 6, 2017 if item:HasTag("edible_"..GLOBAL.FOODTYPE.WOOD) then return true end maybe? Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864299 Share on other sites More sharing options...
Lumina Posted February 6, 2017 Author Share Posted February 6, 2017 Yes ! You are great. My first code didn't work because i didn't understand how this kind of thing work. It's perfect, so much better than adding custom tag for compatibility. Wonderful Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864302 Share on other sites More sharing options...
Ricoom Posted February 7, 2017 Share Posted February 7, 2017 if item.name == "log" then return true end Should also work and allows you to do checks for any item by name Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864513 Share on other sites More sharing options...
Lumina Posted February 7, 2017 Author Share Posted February 7, 2017 Thanks. I'll probably use it to add some items that don't have the FOODTYPE.WOOD but could go in here. Link to comment https://forums.kleientertainment.com/forums/topic/73846-filtering-items-going-into-a-container/#findComment-864539 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