0 votes
by (2.3k points)
edited by

Ok so I've got some code I'm tinkering about with:

Roll a 4 or better
<<set $health = 5>>
<span id='dice-outcome'></span>

<span id='dice-button'>\
<<button 'Roll a die.'>>
	<<set $roll to random(1, 6)>>	
	<<if $roll gte 4>>
		<<replace '#dice-outcome'>>\
			You rolled a $roll. [[Well Done]]
 <<replace '#dice-button'>><</replace>> /% remove button %/
		<<replace '#dice-outcome'>>\
			You missed! The Drone showers your position with
			gunfire! Try Again\
			<<set $health -= 2>>
	<<if $health lt 1>>
	<<goto [[Death1]]>><</if>>

I'm trying to get it to a lot of things.

Basically I want the player to roll the dice.

If the player rolls below a '4' I want 2 health to be deducted.

If the player's health dips below 1 / reaches zero, I want to use the goto command (or something similar) to send him to the death screen.

When I try using this code...

It now throws up the death screen upon the first dice roll being under 4.

Can anyone help. I am a bad programmer, good at story-telling, bad at anything beyond basics. :(

Any gurus of the code out there? You guys are unsung heros for helping me out this far...


My first code success without a total copy paste pasta. Did a LOT of code modifications but it deducts health AND it executes a goto command to the death screen!

It's probably a bit rough, but I leave it up for others to work on and improve with, just like I did.

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.