How do I make a randomizer?


#1

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.


#2

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


#3

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.


#4

@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.


#5

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:


#6

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…


#7

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


#8

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


#9

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


#10


Use this project’s code as a reference


#11

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


#12

They did add strings.


#13

Hahahah = Jeffery


#14

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


#15

It doesn’t actually work.


#16

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


#17

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.


#18

What does that mean now


#19

#20

You edited the json file right