MigratoryCoconuts Posted October 7, 2014 Share Posted October 7, 2014 howdy all, i'm trying to create a mod that adds another companion to the game. this will be able to be fed things for aura effects, such as sanity, light, heat, etc. to do so im giving it an internal inventory with a single slot, and then checking it has an effect-giving item in it, in this case a purple gem. currently, im using inventory's Has function, and its not working at all my code:local function CalcSanityAura(inst, observer) if inst.components.inventory and inst.components.inventory.itemslots then if inst.components.inventory.Has("purplegem",1) then return TUNING.SANITYAURA_TINY end endendhowever, the game crashes when it attempts to run the CalcSanityAura, with the following error /dont_starve/data/scripts/components/inventory.lua:806: bad argument #1 to 'pairs' (table expected, got nil) this is weird for two reasons - first, my code explicitly checks that itemslots (the table that Has() attempts to get 'pairs' from) is NOT nil, and second, the flagged line is 806. this line is not only a seemingly innocent 'end', but also for a function that isn't Has() at all - it's at the bottom of ConsumeByName(), a function i do not call a single time with this prefab anyone have any idea what im doing wrong? any help is greatly appreciated! Link to comment Share on other sites More sharing options...
_Q_ Posted October 7, 2014 Share Posted October 7, 2014 Has item function seems to be used to find items and add next item to the stack, and it returns only number of item not the name.Maybe you could try with FindItems function instead. Anyway if the effect if the item lasts till you give it some other item and items are consumed by the follower you don't need to mess with inventory component at all. Link to comment Share on other sites More sharing options...
DeathDisciple Posted October 7, 2014 Share Posted October 7, 2014 One thing stands out, you will want to use : (class function call) instead of . (table/object reference call),inst.components.inventory:Has("purplegem",1)When you do it that way, it passes self as first argument (the class object, that is, inventory object reference), so the call is actually executed with argument list as if (self,"purplegem",1). The way you called it you effectively made self="purplegem", which is the cause of the error you got (pairs executed on self.itemslots which is nil due to self resolving to a string). As for the line number, I'm going to assume you're running ROG and you're looking at base game source code. ROG is written so it brute force overwrites base files, you should look at /dont_starve/data/DLC0001/scripts/components/inventory.lua:806, which is for k,v in pairs(self.itemslots) do..................................which fits my above explanation. Link to comment Share on other sites More sharing options...
MigratoryCoconuts Posted October 8, 2014 Author Share Posted October 8, 2014 thanks dude! that worked perfectly i guess im still too used to non-Lua languages and the colon notation caught me out Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.