I'm working with Twine 1.4x and Sugarcube 2. I have a menu where the player can install parts to a machine; all parts are objects containing the boolean properties 'have' (whether or not the player has it in their inventory), 'req' (whether or not the player has the requisite skill to install the part), and 'done' (whether or not the part has been installed). At the start of the install passage, checks are run for each part to see if the requirements have been made, and if so, to change the 'req' property to true. It then pushes every part to array '$genParts'. The install menu consists of a list of parts in the player's inventory as links; on click, if 'req' is false, the player gets an alert dialog saying they don't have the skill needed to install the part. If 'req' is true, a confirm dialog will pop-up asking if the player wants to install the part; when the player clicks OK, a few things are supposed to happen: the part is removed from the inventory; 'have' is changed to false; 'done' is changed to true; the part is removed from the inventory array. The only thing that does not seem to work is changing the object properties in the array.
When I click OK to install a part, I get a "cannot set property of undefined" error, so it seems that the problem is in modifying the object in the array. What am I doing wrong?
<<for $i to 0; $i lt $genParts.length; $i++>> <<if $genParts[$i].req is true>> <<click $genParts[$i].name>> <<set $install to confirm('Install this part?')>> <<if $install is true>> <<set $genParts[$i].done to true>> <<set $genParts[$i].have to false>> <<set $partsInv.splice($partsInv.indexOf($genParts[$i]), 1)>> <<endif>> <</click>> <<print "<br>">> <<elseif $genParts[$i].have is true>> <<click $genParts[$i].name>> <<set alert('You don\'t have what you need for this.')>> <</click>> <<print "<br>">> <<endif>> <</for>>
When I click OK to install a part, I get a "cannot set property of undefined" error, so it seems that the problem is in modifying the object in the array. What am I doing wrong?