Simplified Item and Inventory "Remove" function as well as removed non-functional code #477
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Both functions use a loop to remove the item. As far as I can tell this really isn't necessary. In both cases I simply use the item's gridX and gridY member values to find their entry in the Inventory "slots" table to delete them there.
In Item "Remove" function, there is code that would be run when the loop couldn't find the item in the Inventory "slots" table. I've personally never had this happen, additionally the code that is supposed to run, if the loop doesn't find the item, doesn't make sense to me.
First, the Inventory "slots" table (the table that stores its items, with their grid X and Y values as the keys) is emptied.
helix/gamemode/core/meta/sh_item.lua
Line 439 in 418947a
Next. a loop using the Inventory "Iter" function is supposed to loop through all the items stored in the inventory, then populate the "slots" table (but only within the x, y and width & height values of the to-be-removed item?) with the adequate data. However because "Iter" internally uses the "slots" table (which at this point is empty) effectively nothing happens.
helix/gamemode/core/meta/sh_item.lua
Lines 440 to 448 in 418947a
Lastly the changed inventory is meant to be synced to the inventory owner, however the if-condition expects a player object, while the inventory member value "owner" actually returns a character ID (or in general a number, for instance for container inventories), so this if-condition actually causes an error, if it were to be executed.
helix/gamemode/core/meta/sh_item.lua
Lines 450 to 452 in 418947a
To me this appears to be outdated code, leftover from the transition from Nutscript to Helix, so I'd just remove it.