If you are unfamiliar with Candy Box (and its sequel), it’s a game where you gain (at least) one candy per second. Using those candies, once you have enough, you can unlock new parts of the interface, buy items, or simply eat them. If we want to copy some of those mechanics, we need to think about what happens: * The player earns 1 candy every second * The player can eat those candies; decreasing the candy count and increasing candy eaten count * The player can unlock more of the interface [[Earning per second]]Copying the first mechanic is fairly easy. We can use the `(live:)` and `(replace:)` macro to count every second for us. {|counter>[You have 0 candies] (set: $count to 0) (live: 1s)[ (set: $count to it + 1) (replace: ?counter)[You have $count candies] ]} *`|counter>[You have 0 candies] (set: $count to 0) (live: 1s)[ (set: $count to it + 1) (replace: ?counter)[You have $count candies] ]`* [[Eating and selling]]{|counter>[You have 0 candies] (set: $count to 0) (live: 1s) [ (set: $count to it + 1) (replace: ?counter)[You have $count candies] ]} Building on our increasing candy, we also want the ability to eat them. To do that, we can use a combination of the `(click:)`, `(link:)`, `(replace:)`, and `(display:)` macros. *`{(set: $candyEaten to 0)} |eatCandy>["Eat all candies"] (click: ?eatCandy)[ {(set: $candyEaten to it + $count) (set: $count to 0)} (replace: ?counter)[You have $count candies] (replace: ?eatCandy)[(display: "EatCandy1")] ]`* {(set: $candyEaten to 0)} |eatCandy>[Eat all candies] (click: ?eatCandy)[ {(set: $candyEaten to it + $count) (set: $count to 0)} (replace: ?counter)[You have $count candies] (replace: ?eatCandy)[(display: "EatCandy1")] ] [[Updating the interface]] (set: $candyEaten to it + $count) (set: $count to 0) (set: $clickCounter to it + 1) You have eaten $candyEaten candiesYou have eaten $candyEaten candies. (link: "Eat all candies")[ {(set: $candyEaten to it + $count) (set: $count to 0)} (replace: ?counter)[You have $count candies] (replace: ?eatCandy)[(display: "EatCandy2")] ]You have eaten $candyEaten candies. (link: "Eat all candies")[ {(set: $candyEaten to it + $count) (set: $count to 0)} (replace: ?counter)[You have $count candies] (replace: ?eatCandy)[(display: "EatCandy1")] ]|contentDisplay>[] {|counter>[You have 0 candies] (set: $count to 0) (live: 1s) [ (set: $count to it + 1) (replace: ?counter)[You have $count candies] ]} {(set: $candyEaten to 0)} |eatCandy>[Eat all candies] (click: ?eatCandy)[ {(set: $candyEaten to it + $count) (set: $count to 0)} (replace: ?counter)[You have $count candies] (replace: ?eatCandy)[(display: "EatCandy1")] ] {(set: $updateCounter to 20)} |updateInterface>[Buy update for $updateCounter candies.] (click: ?updateInterface)[ (display: "UpdateInterfaceCheck") (replace: ?counter)[You have $count candies] (replace: ?updateInterface)[(display: "Interface1") ] ](link: "Buy update for $updateCounter candies.")[ (display: "UpdateInterfaceCheck") (replace: ?counter)[You have $count candies] (replace: ?updateInterface)[(display: "Interface2")] ](link: "Buy update for $updateCounter candies.")[ (display: "UpdateInterfaceCheck") (replace: ?counter)[You have $count candies] (replace: ?updateInterface)[(display: "Interface1")] ]{(if: $count >= 20)[ (replace: ?contentDisplay)[(display: "displayContent1")] (set: $updateCounter to it + 20) (set: $count to 0) (replace: ?counter)[You have $count candies] (replace: ?updateInterface)[(display: "Interface1")] ]}<pre> ============================================= | | | Health: 100 / 100 | ============================================= </pre>