So I have some code that doesn't work, and I'm not sure why.
<<for $i to 0; $i < $party.length; $i++>>
<<click "Delete Member">>
<<print '<<set $party.deleteAt('+$i+')>>'>>
<<print '<<goto "' + passage() + '">>'>>
<</click>>
<</for>>
In theory, this code should loop through all party members and display a button saying "Delete Member" for each which, when clicked, deletes the member at that index.
However, rather than deleting the member at index $i, like it's supposed to, it deletes the member at $party.length resulting in an out-of-bounds error.
Obviously this means that $i is not being "memorized" by the print statement as it should be... Why is that? How can I fix it? I'm at a bit of a loss.
Comments
I had tried capturing the entire thing before and it didn't work, hence my confusion.
Well, that's unfortunate. Temporary variables don't seem to be in SugarCube 1.0.34, so I've switched to 2.6.2 for now.
Beyond that, the <Array>.deleteAt() method only exists in SugarCube 2, so I'm confused as to how you were supposedly using it in v1 to begin with. That's why I suggested the use of temporary variables—which, yes, are not in v1—since it seemed like you were using v2 already (which is at v2.7.0).