whismerhill Posted June 17, 2016 Share Posted June 17, 2016 hi, so my code has a loop that goes through all inventory items. I verified that item is not nil already however I got a rare crash where this code : if (item["Light"] or recipes[item.prefab].tab == RECIPETABS.LIGHT then returned an error because can't index nil. so I'm wondering if I should check that item.prefab is not nil globally or locally e.g. can a valid item have no prefab ??? I'm wondering cause so far I can't reproduce the crash. Thanks. Link to comment https://forums.kleientertainment.com/forums/topic/68259-can-an-item-in-inventory-have-no-prefab/ Share on other sites More sharing options...
Mobbstar Posted June 17, 2016 Share Posted June 17, 2016 maybe the item itself is nil? Anyways, some dummy prefabs spawn before anything else and don't have a prefab name. Link to comment https://forums.kleientertainment.com/forums/topic/68259-can-an-item-in-inventory-have-no-prefab/#findComment-785103 Share on other sites More sharing options...
whismerhill Posted June 17, 2016 Author Share Posted June 17, 2016 (edited) well I don't think it's possible since there's a : "if item then" before that and ok that means I should be safe to verify that all items in inventory have a prefab globally before it process any of them. if item and item.prefab then thanks. Edited June 17, 2016 by whismerhill Link to comment https://forums.kleientertainment.com/forums/topic/68259-can-an-item-in-inventory-have-no-prefab/#findComment-785119 Share on other sites More sharing options...
DarkXero Posted June 17, 2016 Share Posted June 17, 2016 On some very particular circumstances, the prefab of an item can be nil, I guess. But that's not the issue here at all. Not all items have recipes. recipes[item.prefab] is nil if the item can't be crafted. Link to comment https://forums.kleientertainment.com/forums/topic/68259-can-an-item-in-inventory-have-no-prefab/#findComment-785252 Share on other sites More sharing options...
whismerhill Posted June 18, 2016 Author Share Posted June 18, 2016 (edited) well I agree with you darkxero however why would that be a problem at all ? you mean it can't do the operation : " nil == somevalue " and so return false ? so before doing that I should add something like if (item["Light"] or function(item,recipes) if recipes[item.prefab] then return (recipes[item.prefab].tab == RECIPETABS.LIGHT) else return false end end) then ho while writing it I realize that maybe what it doesn't like is the ".tab" over a nil value ? sorry I'm a bit of a newb Edited June 18, 2016 by whismerhill Link to comment https://forums.kleientertainment.com/forums/topic/68259-can-an-item-in-inventory-have-no-prefab/#findComment-785488 Share on other sites More sharing options...
Mobbstar Posted June 18, 2016 Share Posted June 18, 2016 2 hours ago, whismerhill said: however why would that be a problem at all ? Just do something like you do for whether the item exists at all: if (item["Light"] or (recipes[item.prefab] and recipes[item.prefab].tab == RECIPETABS.LIGHT) then Link to comment https://forums.kleientertainment.com/forums/topic/68259-can-an-item-in-inventory-have-no-prefab/#findComment-785527 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