Assign output to a variable?


#1

Hi, my 7yr old son is really loving Hopscotch and uses it most days. Today he asked if there was a game he could make for me. So I suggested a game where there were 5 cards per player (2 player). Player 1 chooses a random card and a number is displayed. Player 2 does the same. What we want to do now, is assign those random numbers to a variable, do a comparison and display either Player 1 or Player 2 wins depending on who has the highest number.

Can anyone please help and suggest how to assign the number to a variable?

Thanks :slightly_smiling:


#2

Hi! So, are you saying: 2 people have 5 cards each, each person chooses a card, and whichever card higher wins?


#3

I believe you could make the code as follows:
When (Player 1) is tapped
Set value (Player 1) to (random(1) to (10))
Set text to (Player 1)

This code sets a value to a random number and then displays that random number when tapped.
You can then use "Check once if" blocks to compare the two variables.
I hope this has helped!


#4

or when (card that was tapped)

To go deeper, "check once if" (the card that was just picked) is greater than (p2 card)
If yes, p1 wins


#5

Wow, thanks for the quick replies!! We'll work thru that now...


#6

No problem! If you need further assistance, you can always ask me on hopscotch. (My username is Follow 4 Likes Official)