How do I make a randomizer?

I’ve been looking for a way to make a randomizer for one of my games. I want it to do a random emoji whenever you click a box, like a fortune cookie. I saw a post saying you need to use a set value block but I don’t have those. I’m posting this here because it won’t let me in Deprecated. Thanks.

11 Likes

Do you mean like the box turns in to the emoji or the emoji is a different object?

2 Likes

All you have to do is put in the box code:

When SELF is tapped

Set variable (variable) to random 1 to (the number of different types of emojis you want)

Then put in the emoji object’s code

When (variable)=1

Set text to (the emoji you want)

Do that with every possible number that (variable) can be.

5 Likes

@Fundardo posted the answer that you need! You basically just need to make a new variable, then make it to a random number and use “when (variable) equals ___” togheter with “Set text” blocks and you are done.

3 Likes

Yeah, everyone’s basically answered your question – the reason why you don’t have a “set value” block is because variables were originally called “values” so the block names have changed a bit. :slight_smile:

Easy-
When self is tapped
Set variable(name) to random 1 to (whatever you want)
Then get a text.
In its code,-
When (variable name)=1,
Set text to(emoji)
When(variable name)=2
Set text to(emoji)
When(variable name)=3
Set text to (emoji)
And so one…

2 Likes

I’m really confused. I made the variable, but I don’t get the rest. Sorry, I’m bad at coding.

1 Like

Alright, I figured out how to make it random, but how do I get the object codes?

1 Like

What do you mean by objects?do you mean the emoji that comes up?

https://c.gethopscotch.com/p/zgnhpmn6o
Use this project’s code as a reference

1 Like

It makes me sad why Hopscotch can’t add arrays and strings ugh this is why I code on JavaScript

1 Like

They did add strings.

https://c.gethopscotch.com/p/zileqy4or

3 Likes

Hahahah = Jeffery

1 Like

Woah!how did you do that!I want to use the strings feature

It doesn’t actually work.

1 Like

Why not? It works fine for me. You must have made a mistake

Well you can’t actually do what strings normally can do. Like you can’t do Set String to Hello and do Set Text String and have it display the string.

1 Like

What does that mean now

https://c.gethopscotch.com/p/znv0mm66l

3 Likes

You edited the json file right