How to get an object (a cat) to say something based on a random selection of a set of phrases


I am new to coding and CoSpaces but I wanted to recreate a play on a magic 8 ball - the initial ideas is that the user will engage with the merge cube by clicking a button), however later if possible it would be good to display this text if the cube is shaken (though I am unsure if this an option!)

So I have created a merge cube environment with on the front I have a button which the user can click. On the top of the cube, I have a cat. When the button is clicked, the cat will say one of 20 responses randomly selected from a set list of responses.

The idea is a slightly edited version of this scratch exercise (see image). However, since CoBlock is a bit different from Scratch I cant seem to figure how to set the responses and for the cat to say them.

Any suggestions?

Hi @Kate_M,

You could create a list of phrases, then generate a random number and use say CoBlock to say a phrase from the list. Please, refer to this tutorial to learn how to use lists in CoSpaces.

Hope that helps!

1 Like

Hi @Kate_M,

You can create a list of phrases using some of the List CoBlocks (under Data > Lists). First create an empty list, then add some Text values (under Data > Values) to it.

From there, it should be plain sailing, as very similar CoBlocks exist for most of your Scratch code.

Let me know how you go. I could create the whole thing for you, but I don’t want to spoil your fun (and learning)!

Best of luck,
Geoff @ TechLeap

1 Like

Thank you for your help, I managed to create it - CoSpaces Edu :: Magic 8 Ball reimagined, if you are interested in how it turned out :smile:

I couldn’t see any phrases you mentioned, and nothing happened when I clicked on the answer - have you published the updates (you need to re-share by clicking Share > Update every time you make a change to a published CoSpace).

Geoff @ TechLeap

Mmhh, the idea is that if you click on the box, the rabbit will ask you to state your question - I haven’t integrated the textbox activity- not sure if I will add that (if I can work out how) - but after 5 mins it will generate a random response based on the 20 set answers.

I have just rechecked and it works for me. Have I missed something?

Ah, that wasn’t obvious - it says click to get your answer, so I expect that I ask a question then click to get an answer (rather than click to get an answer then ask a question). How could you improve the user interaction or help text, so that it’s clear to the user/player how to use your CoSpace app?

Geoff @ TechLeap

PS: As a side-note, it would be cool if the CoSpaces API could detect when the Merge cube is shook…

Ah good point, I have updated it a bit so the interaction was a bit more clear.
I had seen that there was some conversation around a shake API on the forum back in 2018, but it looks like its still, not an option yet. This was my workaround.