Magic 8

Magic 8

Let the Calliope mini tell you the future.

Easy

30 mins

from 8 years on

In this exercise we'll use the Open Roberta editor. Make sure that you see this picture in the upper right corner of your programming environment. The editor can be found on our website at the top of the navigation bar: Let's start - Editor.

First steps: Fortune telling ball

Dein Calliope mini kennt die Antwort.

1Setting variables

First, you create a variable. Click on the + symbol in the Start block. Then name the variable with random.

2Question mark

To display a question mark at the start of the minis, take the show text block you find under action, change text to character and enter a question mark.

3Infinite loop

Select the following block in the menu under control to play your following code in an endless loop.

4Setting conditions

Now select the if - do block under control to set the condition. Then add the get shaking gesture from the sensors menu to control the position sensor. In the selection change upright to shaken.
Next, select the set random block from the variables menu. To these you add the integer random value between 1 and 100 block, from the math menu, change the 1 to a 0** and the 100 to a 3.
Now the value of the variable random is randomly set to a number from zero to three.

5Setting the answer

Now add another if - do block and add the block = from the logic menu to it. Now you fill the block with the random variable, from the variables menu and a 0 to set the condition for the value zero of the variable. Then take a show text block and enter your answer in the text box.

6More answers

You can duplicate this if - do block four times. To do this, right-click on the if - do block and choose copy. For the further random numbers 1-3 of your duplicated blocks you can now define the statements. In each of the three blocks, make the following statements:

  1. change the random number
  2. enter your text
  3. put your blocks together
7Pause

So that you have a little time to display the next answer, you can include a pause. For this you take the wait ms block, which you can find under control. Try different waiting times until you like a period.

8Done

To display a question mark after the answer again, add a show text block at the end. Now all you have to do is change text to characters and enter the question mark in the text field.

Done - download your script and try it out!

Hier findest du die fertige Datei!

Dieses Programm kann direkt im Editor geöffnet werden.