whismerhill Posted October 15, 2016 Share Posted October 15, 2016 Hi, is this really normal that say, equippeditem.components.tool:CanDoAction(action) returns true when say holding a torch (equippeditem) & picking a sapling (ACTION.PICK) I mean sure the character can do that but he's not actually using the tool to do the action, beside the torch isn't even a tool to begin with..... the code : Spoiler local function FindTool(inventory, action) local alreadyequippeditem = inventory:GetEquippedItem(EQUIPSLOTS.HANDS) -- get what's in our hands -- escape finding another item if item equipped can already do the job and exists (e.g. it's not bare hands) if alreadyequippeditem and alreadyequippeditem.components.tool and alreadyequippeditem.components.tool:CanDoAction(action) then return end return inventory:FindItem(function(item) return item.components.tool and item.components.tool:CanDoAction(action) end) end so this works perfectly mind you, so it's not like I'm asking for any real help to fix something, but I would still like to understand though. If for any reason I remove the "alreadyequippeditem.components.tool" check then a torch or weapon will : return true to "alreadyequippeditem" check (as expected, since they are not nil) and will also return true to "alreadyequippeditem.components.tool:CanDoAction(action)" check (not expected, since the component tool doesn't even exist I would have expected an error instead). Link to comment Share on other sites More sharing options...
Mobbstar Posted October 15, 2016 Share Posted October 15, 2016 This sounds highly peculiar. You should use "print" to get more information on this, like so: print("FindTool item", alreadyequippeditem) Link to comment Share on other sites More sharing options...
whismerhill Posted October 15, 2016 Author Share Posted October 15, 2016 nevermind my mistake, it does produce an error, but it doesn't crash the game, and the mod scripts just continue working which makes it behave as if the conditions were true, when in fact the whole checking & "escape" was just skipped. the code & error : Spoiler if alreadyequippeditem and alreadyequippeditem.components.tool:CanDoAction(action) then return end ../mods/auto_equip/scripts/auto_equip.lua:43: attempt to index field 'tool' (a nil value) again, emphasis how this is treacherous, it just skips the condition & continue code execution, with the mod in question behaving normally apart from a few cases concerned by this. note how : "and alreadyequippeditem.components.tool" is missing unlike my first post. Thanks Mobbstar, I'm happy to have found a reasonable explanation to this. xD (posting my findings for future potential readers ) Basically my main error was to not check the logs or console, too used to almost all lua errors just crashing outright DS 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.