Move a player based on RandomNumberGenerator?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cadam

I’m wondering if it’s possible to move a character (2D-Scene with a grid/tile-map) based on the result of a RandomNumberGenerator?
The player rolls the dice (on_Button_pressed) and gets a random number (let’s say: 6).
Is it possible to store that number in a variable so that it can be used for Vector2D-movement on a grid (on_MouseInput)? If so, the player should only be permitted to move 6 tiles up/down/left/right.
How would you solve this?

:bust_in_silhouette: Reply From: exuin

Yes, you can store the result of a random number generator in a variable. As for movement, just limit the distance the end tile can be from the start tile by the randomly generated number times the tile size. What specifically do you need help with?

How would storing the result of the randomly generated number into a Vector2D look like?

cadam | 2021-03-05 10:18

You wouldn’t store it as a Vector2, you would store it as an int.

exuin | 2021-03-05 13:53

Ok, but how would you go on code-wise?
So, I have received my random number (random_number = 6) and want to tell the player that he/she is now allowed to move, for example, 6 fields left/right/up or down.
That’s where I’m struggling.

cadam | 2021-03-05 17:14

What do you mean, tell the player? Do you want to just display a big number “6” on screen?

exuin | 2021-03-05 19:39