0 votes
by (390 points)
edited by

I am working on a combat system with multiple opponents. In order to create a "turn based" system in which each combtant takes their turn, I have established an array with all of the applicable characters involved. That would be, for example:

(set:$group to (a:$hero,$opp1,$opp2,$opp3))

In which the elements are datamaps that contain information like hit points (HP), weapon damage, and other values that are involved with the combat math.

What I want to do, through combat is remove one of the items from that array when that item's HP is at or below zero. The code I have is currently: 

(if:$opp1's hp is <=0)[(set:$group to it - (a:$opp1))]

The idea being that as the rounds continue, $opp1 would be removed from the sequence and their turn skipped until all enemies are killed.

However, when I "kill" an opponent--$opp1-- the array $group retains $opp1 and shuffles them through the sequence of combat.

Here is a truncated version of the code I am using...

<!-Combat Init-!>
(set:$turn to 1)
(set:$group to (a:$hero,$opp1,$opp2,$opp3))
(set:$attacker to $group's ($turn))

<!-Combat Screen-!>
(link:'Attack')[(set:$target to $opp1)(goto:'Combat Roll')]
(link:'Attack')[(set:$target to $opp2)(goto:'Combat Roll')]
(link:'Attack')[(set:$target to $opp3)(goto:'Combat Roll')]

<!-Combat Roll-!>
(set:$attroll to (random:1,20))
(set:$attrolltot to $attroll + $attacker's weapon's bonus)

(if:$attrolltot is >=$target's body)[
(if:$target is $opp1)[(set:$opp1's hp to it - $attacker's weapon's dam)
(if:$opp1's hp is <1)[(set:$group to it - (a:$opp1))]]

(if:$target is $opp2)[(set:$opp2's hp to it - $attacker's weapon's dam)
(if:$opp2's hp is <1)[(set:$group to it - (a:$opp2))]]

(if:$target is $opp3)[(set:$opp3's hp to it - $attacker's weapon's dam)
(if:$opp3's hp is <1)[(set:$group to it - (a:$opp3))]]

(if:$target is $hero)[(set:$hero's hp to it - $attacker's weapon's dam)]

(set:$turn to it + 1)(if:$turn is > $group's length)[(set:$turn to 1)]
(set:$attacker to $group's ($turn))

(goto:'Combat Screen')

Is this method possible to have a turn-based sequence for combat? Is there a better way to do sequencing for multiple combatants than to use arrays?



1 Answer

0 votes
by (6.2k points)
I don't understand the question. Does this code not work or are you looking for a better solution?
by (390 points)
edited by
It did not work, I apologize for the confusion. I will modify my query accordingly with additional code.

When I "kill" the opponent, the array $group contains all of the previous datamaps/variables/items.

If there is a better solution, I am all ears.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.