Created
April 1, 2024 03:15
-
-
Save desplesda/a6ac664f38f42f2555cf3c4361769fd0 to your computer and use it in GitHub Desktop.
Combination Lock for books.yarnspinner.dev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title: Start | |
--- | |
// Paste this gist into https://books.yarnspinner.dev and click Download Book! | |
You hold in your hands a combination lock. Can you unlock it? | |
<<set $col1 = 0>> | |
<<set $col2 = 0>> | |
<<set $col3 = 0>> | |
// Decide the maximum value each column can be. (Yarn Spinner for Books only allows loops of a certain size, so 3 is the maximum supported value.) | |
<<set $maxColumnValue = 3>> | |
// Pick random integers between 0 and maxColumnValue as our solution | |
<<set $solution1 = dice($maxColumnValue+1)-1>> | |
<<set $solution2 = dice($maxColumnValue+1)-1>> | |
<<set $solution3 = dice($maxColumnValue+1)-1>> | |
<<jump Code>> | |
=== | |
title: Code | |
--- | |
<<if $col1 == $solution1 && $col2 == $solution2 && $col3 == $solution3>> | |
// The player got the right solution! | |
With a click, the lock pops open. You've done it! | |
<<stop>> | |
<<else>> | |
// Show the current state of the lock | |
The combination lock reads: {$col1}-{$col2}-{$col3} | |
// Turning a number will increment it, and wrap back to zero if it goes too high. Then, jump back to this node and show the updated state. | |
-> Turn the left number | |
<<set $col1 += 1>> | |
<<set $col1 %= $maxColumnValue + 1>> | |
<<jump Code>> | |
-> Turn the middle number | |
<<set $col2 += 1>> | |
<<set $col2 %= $maxColumnValue + 1>> | |
<<jump Code>> | |
-> Turn the right number | |
<<set $col3 += 1>> | |
<<set $col3 %= $maxColumnValue + 1>> | |
<<jump Code>> | |
<<endif>> | |
=== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment