Links from arrays in Twine sugarcube 2.34.1

If you are requesting technical assistance with Twine, please specify:
Twine Version:2.3.14
Story Format: sugarcube 2.34.1

Hi there i am new to Twine and i am trying to implement a fight logic to my story. I have an inventory stored in an array of strings. Depending on the item selected the logic will be diferent. I have created links from the array but i cant find the way to specify where i want them to be linked separately.
Here i create the array

<<set $enemyAttack to [“a knife”, “a gun”, “a stone”, “a rock”]>>

Here i display the links

<<for _i to 0; _i lt $enemyAttack.length; _i++>>
<<set _link to $enemyAttack[_i]>>


And from there i have no idea how to keep implementing my code as if the link is for example “a gun” i want to develop a type of attack diferent than with the knife.
Thanks in advance

You may try

<<set $enemyAttack to ["a knife", "a gun", "a stone", "a rock"]>>

There's a man standing right behind you. You only have time enough to draw a weapon.
<<for _i to 0; _i lt $enemyAttack.length; _i++>>
<<set _link to $enemyAttack[_i]>>
You want to draw <<link _link _link>><</link>>

It should send the reader to a passage dedicated to each specific weapon.

I’ve edited my answer.

The code will send the player either to a passage named “a knife”, or “a gun” etc.

Then you could write and code whatever you need in each of those.
For instance “a knife” passage might start like this ($character_melee should have been set):

You draw your knife as quickly as you can and swing it before your opponent.
<<set _dice to random(1,6)>>
<<if _dice gt $character_melee>>You cut your opponent's arm.<<else>>Your opponent dodges your weapon<</if>>

Ok thanks a lot so now i will have the links. But how i make them attack when i click them? Im a bit lost thanks

The attack comes with the new passage. How the attack works is up to you, it depends on what you have in mind as a test. You’ll probably need macros like <<if>><</if>> ( and functions like random() or either()( and And variables to describe the player and the opponent.

This is what i have and atm is attacking 4 times everytime i press any of the links

You: $playerReaminingLife/100 <>

<<for _i to 0; _i lt $enemyAttack.length; _i++>>
<<set _link to $enemyAttack[_i]>>

	<<set $atk to "_link">> 

<<set $playerAttackDamage to random(1, 10)>> 
<<set $monsterRemainingLife -= $playerAttackDamage>>

<<set $turn to "enemy">> 

<<set $log to "atk">>


<<set $atk to “Punch”>>

<<set $playerAttackDamage to random(1, 10)>> 
<<set $monsterRemainingLife -= $playerAttackDamage>>

<<set $turn to "enemy">> 

<<set $log to "atk">>

<<elseif $turn is “enemy”>>

<<link “Continue”>><<goto “Combat”>>

<<set $log to "enemy">>

<<set $turn to "you">>
<<set $monsterAttackType = $enemyAttack.random()>>

<<set $monsterAttackDamage to random(1, 15)>>

<<set $playerReaminingLife -= $monsterAttackDamage>>



<<if $playerReaminingLife < 1>><<goto “Lose”>><>
<<if $monsterRemainingLife < 1>><<goto “Win”>><>

Uauh is working!!! Thanks a lot i apreciatte your time, help and pattiente. Can i ask you why is puting the “a” before the weapons. ex “You want to draw a knife”

My pleasure !

I put an 'a ’ before knife only because you did so when first declaring your array.

jajajajajaaa so stupid i am. Thanks again