You may place the loop within the <<link>> before or after the replace code. I'm unsure what you've tried previously, however, there should be no problems doing so. If you can show what you've tried, we can probably tell you what's wrong.
That said. Your loop example is needlessly complicated and kind of broken.
- You should likely be using a temporary variable for your loop index.
- You should be using <<break>> after adding the shotgun, rather than modifying $count.
- You're using <<print>> unnecessarily here.
- Where you currently have <<break>> now should probably be a <<continue>>, otherwise the first member which isn't "empty" or "shotgun" will end the loop. That said, since there's no additional clauses an nothing after the <<if>> in the loop, you don't need the <<else>> clause or <<continue>> at all.
- This may or may not be an issue, however, you're not checking to see if a member with the value "empty" comes before one with "shotgun", which would mean that you could add multiple shotguns. That may not be possible with how you're using this or may be intended, so disregard this entry if either is true.
An example of what it should probably look like (without changing it too much):
<<for _i = 0; _i < $weapons_vect.length; _i++>>
<<if $weapons_vect[_i] is "empty">>
<<set
$weapons_vect[_i] to "shotgun";
$weapon_damage[_i] to 5;
$weapon_equip to $weapons_vect[_i];
$weapon_equipdamage to $weapon_damage[_i]
>>
<<break>>
<<elseif $weapons_vect[_i] is "shotgun">>
You already have a shotgun.
<</if>>
<</for>>
Then again, have an array populated with the string "empty" is already kind of bizarre, so…. I'm assuming it's supposed to be representing fixed slots or something to that effect.
That said, if you're going to be using the loop in multiple places you may wish to make a widget out of it. For example: (goes in a separate widget-tagged passage)
<<widget "addweapon">>\
<<silently>>
<<set
_weapon to $args[0];
_damage to $args[1];
_error to ""
>>
<<for _i = 0; _i < $weapons_vect.length; _i++>>
<<if $weapons_vect[_i] is "empty">>
<<set
$weapons_vect[_i] to _weapon;
$weapon_damage[_i] to _damage;
$weapon_equip to _weapon;
$weapon_equipdamage to _damage
>>
<<break>>
<<elseif $weapons_vect[_i] is _weapon>>
<<set _error to "You already have a " + _weapon + ".">>
<</if>>
<</for>>
<</silently>>\
<<if _error>>_error<</if>>\
<</widget>>
Usage would be:
<<addweapon "shotgun" 5>>