casey 13 Report post Posted January 19, 2018 I have an array of items (stored as strings) I am displaying on screen as sprites, in an inventory. I want to update my array when an item is removed from my inventory, so I want to write a function that resets the x position of the objects. I can log out the right object and the right index value, but I can't seem to set the position of the object using this function. Any ideas ? example: inventory('key', 'rock', 'sword', 'note'); resetSlots: function() { //for every item in inventory, slot position is index number. inventory.forEach(function(item, index){ item.x = index * 150; console.log(item.x); //this returns "undefined" }) }, Quote Share this post Link to post Share on other sites
Zenext 1 Report post Posted January 19, 2018 What objects does inventory contain? You can't set the position because 'item' does not have property 'x'. So I assume item is not a sprite but some other object? Quote Share this post Link to post Share on other sites
casey 13 Report post Posted January 19, 2018 I just realized this problem. The items are stored as strings in the inventory, where the string name matches the sprite name, but i need to store the sprite without the string quotations. Thanks! Quote Share this post Link to post Share on other sites