Dantekris2013 Posted March 2, 2021 Share Posted March 2, 2021 (edited) Hello. I want to make a character who will refuse to eat spoiled food, monster meat and raw meat. When character eating a raw or fried mandrake, this error flies out. I can’t understand what’s wrong. I would be very grateful for any help! valentino.lua Edited March 2, 2021 by Dantekris2013 Link to comment Share on other sites More sharing options...
Bigfootmech Posted March 2, 2021 Share Posted March 2, 2021 (edited) attempt to index field 'perishable' (a nil value) you tried to access something on a variable called "perishable". But it failed. Because "perishable" is not a table, in fact, it's even a nil (doesn't exist)! [string "../mods/Valentino/scripts/prefabs/valentino..."]:102 it happened in the file you uploaded, in line 102 looking at your code, line 102 is: and ((inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled()) Ok, so then, what is this inst, that it couldn't find a perishable component on it? inst.components.eater.PrefersToEat = function(self, inst) --V2C: fruitcake hack. see how long this code stays untouched - _-" return not (inst.prefab == "winter_food4" and self.inst:HasTag("player")) and self:TestFood(inst, self.preferseating) and not (self.inst:HasTag("pickyeater") and ((inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled()) or inst.prefab == "monstermeat" or inst.prefab == "cookedmonstermeat" or inst.prefab == "monsterlasagna" or inst.prefab == "monstermeat_dried" or (inst:HasTag("edible_MEAT") and inst:HasTag("cookable")))) end So, this is a little confusing (I've not touched that part of the codebase yet), but I'm assuming "inst" in line 102 is supposed to be the food being eaten in the case you stated, "raw, or cooked mandrake" But as far as I know, neither of those spoil. Nor does rot. So I wouldn't expect them to have a "perishable" component. So if you set line 102 to be this instead: and ((inst.components.perishable ~= nil and (inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled())) I think it should work Basically: check that the food HAS a perishable component. If it doesn't, then it can't be stale, or spoiled, so it's ok It might also help you long-term if you split the whole reaturn logic statement in to more readable parts. But that's up to you Edited March 2, 2021 by Bigfootmech Link to comment Share on other sites More sharing options...
Dantekris2013 Posted March 2, 2021 Author Share Posted March 2, 2021 Oh it really worked! Thank you so much Bigfootmech you are incredible!! 1 Link to comment 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