# Need help with ifelse loop for a fight

0 votes
Hello all!

I am new to Twine and SugarCube. I am writing a "Pen and Paper solo adventure" and i am stuck unfortunately. I just can't figure out how i have to use the ifelse loop for a fight. I have several actions during a fight. The question if the player hit the target (Yes/no), then entering the amount of damage the player did via player input, or skip the player input, if the player missed the target and after that the damage the target does to the player. And of course the damage the target does to the player. Here is a not that good example what i mean:

<<if>> \$target < 0 (if the target is dead)

Gratulations! You beat the example boss

or \$healthpoints < 0

You are dead, noob

<<else>>

Did you hit the target?

<<button Yes >><</button>>

\$target -= 5 <<else>>

You hit the target.

The target hits you with XY amount of damage

\$lifepoints -= 10

<<else>>

You missed the target!

The target hits you with XY amount of damage

\$lifepoints -= 10

I hope this is somehow understandable. It's very hard to explain what i need sonce english isn't my native language. I still hope than someone can help me. I am sitting here since hours but unfortunately i can't really find a usefull guide or how to or video. Can someone please help me?

## 1 Answer

0 votes
by (8.9k points)
selected by

Best answer
``````<<if \$target lt 0>>
<<print "Gratulations!  You beat the example boss.">>
<<elseif \$healthpoints lt 0>>
<<print "You are dead, noob">>
<<else>>
<<button "Attack the target" `passage()`>>
<<set \$coinToss to either ("heads", "tails")>>
<</button>>
<<if \$coinToss == "heads">>
<<set \$target -= 5>>
<<set \$healthpoints -= 10>>
<<print "You hit the target!  The target hits you with 10 damage.">>
<<elseif \$coinToss == "tails">>
<<set \$healthpoints -= 10>>
<<print "You miss the target!  The target hits you with 10 damage.">>
<</if>>
<</if>>``````

by (390 points)
I love you! Works like a charme. Perfect! Thank you really really really much! <3
by (8.9k points)
I love you too, Haaku!