So my approach to changing equipment in my RPG is going to look something like this:
You are using $Weapon.
You have these weapons:
(set: $iterator = 1)
(live: 2ms)[
(link-goto: $OwnedWeapons's $iterator, "Change Equipment")
(if: $iterator + 1 > $OwnedWeapons's length)[(stop:)]
(set: $iterator to $iterator + 1)
]
The thing that is troubling me is how I can get the game to know which link they click on. I don't want to develop a unique passage for equipping every piece of gear in the game. Anyone have any ideas about a way to implement this?
Comments
a. All the links your example creates will overwrite each other, one way to get around this issue is to use a named hook and (append:) macro combination.
b. It does not handle the case when there are no items in the $OwnedWeapons array.
c. It increments the $iterator variable after it has finished processing the array.
A better version of your example, I added line-breaks and indents to make it a little more readable but those can be safely removed.
2. You can replace your (link-goto:) macro with a (link:)/(set:)/(goto:) combination which will allow you to use a variable (eg. $item) to store which item was selected.
3. But the first thing you will notice is that $item will always equal the same value and this is because the value of $OwnedWeapons's $iterator within each link's (set:) macro is determined at the time the link is selected, not at the time the link was created.
You can use a (print:) macro to dynamically create String that represents the (link:) (and its contents) which will allow you to insert the current value of the $iterator variable at the time the link is created. You will need to convert the $iterator variable from a Number to a String so that it can be appended to the (link:) String, you will also need to replace the double quotes delimiting the "Change Equipment" with single quotes.
Now if you check the value of $item within the "Change Equipment" passage it should contain the correct value.