Rolling dice in ARIS

As I’ve been building ARIS games, I keep running into situations where I’d really like the player to roll a dice. And I’ve come up with a couple different ways to include a pseudo-randomizing function.

For instance, during a game launch with a class of students this spring, they all made it through the game at the same speed and wound up queueing in front of one QR code.

This is okay when there are 2-3 people trucking through your game, but picture say... 14 or so. Clumpage!

This is okay when there are 2-3 people trucking through your game, but picture say… 14 or so. Clumpage!

Sure, I should probably design less linear quest narratives, but in that group-play situation, what I’d really like is to spread the players out across the locations on the playing field. I can see two possible easy ways to make this happen: Ruby or Twine.

Let’s take Twine first. Twine uses visual programming plus basic variable-handling to spit out straight HTML files that you can pull into an ARIS game by making them WebObjects.

So. Say you’re playing the “Frogworld” game, where you have to learn about four different kinds of frogs by physically visiting their exhibits.  Your player could click on the WebObject and read:

frogworld

But the next player to click on it might get:

frogworld2

Try it. Click either of the boxes above and see if you get the same frog, or a different frog. Each time you reload the page, the frogs randomize. Well, they pseudo-randomize. Here’s the terrifyingly simple code for this tiny dice as you’d write it in Twine:

Head upstairs to the Frogworld exhibit and go to the  <<print either(“Blue Poison”,”Vietnamese Mossy”,”Malaysian Reed”,”Eastern Cricket”,”Coastal Tailed”)>> Frog tank first.

Boom! Done. But that’s kind of boring.

What if, for instance, you were writing a game called Dino Scramble, where players played as one of five different types of dinosaurs, trying to scramble their way to the finish line while eating or destroying everything in their path? You’d want to randomize the player to a type of dinosaur and potentially store their dino-type in a variable to refer to later. That’d be pretty awesome.

And you’d want dinosaur pictures!

dinoscramble

Click it! Reload! Reload some more! I had way too much fun finding those dinosaur pictures. They totally need some love.

And the code’s very easy for that on Twine as well:

<<set $dino_type to either (“tyrannosaur”, “brontosaurus”, “diplodocus”, “triceratops”, “stegosaurus”)>>

You are a <<print $dino_type>>!

<<if $dino_type eq “tyrannosaur”>>
[img[tyrannosaur.png]]
<<elseif $dino_type eq “brontosaurus”>>
[img[brontosaurus.jpg]]
<<elseif $dino_type eq “stegosaurus”>>
[img[stegosaurus.jpg]]
<<elseif $dino_type eq “triceratops”>>
[img[triceratops.jpg]]
<<elseif $dino_type eq “diplodocus”>>
[img[diplodocus.jpg]]
<<endif>>

(I tossed this on GitHub as a Gist, in case anyone wants to run hogwild with the stored-variables-in-ARIS idea.)

Another way to roll the dice would be with these couple lines of Ruby:

variety = [“stegosaurus”,”tyrannosaur”,”brontosaurus”,”triceratops”]
color = [“green”,”red”,”gold”]
random_dino = variety.shuffle[2] + ” ” + color.shuffle[2]

puts random_dino

Although then you have to wrestle with Sinatra.

Anyway, I’m guessing there are similar ways to do this in a dozen other languages, but I thought this would be some useful code to post for other ARIS people who might not want to learn either language, but have a large pile of dinosaurs sitting around needing to be randomized.

Posted under: Resources

Tagged as: