0 votes
by (160 points)

So I've tried my hand at making a simple combat system.

 

The combat passage looks like this- 

 


<<include "combat">>
<<if $firstAttack is true>>
You are attacked by a $monster.name!<br><br><</if>>

$text<br><br>

The monster's health is $monster.hp!<br><br>

Your health is $health.<br><br>



<<if $monster.hp > 0 and $health > 0>>
<<button "Fight" "attack">>
	<<set $monster.hp to $monster.hp - $weapon.basedamage>>
	<<set $health to $health - $monster.basedamage>>

	<<set $monster.hp to Math.clamp($monster.hp, 0, 100)>>
	<<set $health to Math.clamp($health, 0, 100)>>
		<<set $firstAttack to false>>
		<<set $text to "You hit the $monster.name for $weapon.basedamage! 
       <br><br> The $monster.name hits you back for $monster.basedamage!">>
		<</button>>
		
<<if $firstAttack is true>>		

<<button "Run Away">><<script>>Engine.backward();<</script>><</button>>
<</if>><</if>>
		
<<if $monster.hp is 0>>
You defeated the monster!<br><br>
<<return>><</if>>

<<if $health is 0>>
You were killed by the monster!<br><br>
<<button "Next" "Dead">><</button>><</if>>

When I go through the combat, say I start with 100 health, and the goblin attacks, my health stat is always a turn behind. So, if it gives me 3 damage and I already have 95 health, during that turn it supposedily hit me, my health stays at 95. Then the next turn the monster hits me at 2 damage, it says I have 92 damage until the next hit. 

I don't know if I need to show the rest of the passages that make up the combat since it just sets your weapon damage and enemy damage, but I will if I need to.

Please log in or register to answer this question.

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.
...