# Create roll a dice app

i wanna show you how to create "roll a dice" app in app inventor.
first, create a new project in app inventor.
then, go to design section
add 1 button and 1 image.
button 1 for roll a dice and image 1 for dice number

then go to block section

use this blocks
and result

AIA File For Test
roll_a_dice.aia (8.3 KB)
All images used in project

and video tutorial

This seems to be a blatant copy of:

https://community.appinventor.mit.edu/t/how-to-roll-six-and-share-the-roll-using-a-clouddb/62472/2

2 Likes

This is a simple project and is used for moments we don't have dice, and it is much easier than @SteveJG project

Thanks for your efforts, but i dont think it's a good tutorial, since this IF THEN ELSE IF block is not necessary, just a JOIN TEXT block will do same work.

You mean without pictures?
Because if we have pics we've to use that kind of structure

Please learn how to use AI2 before trying to teach others, otherwise you are just spreading incorrect information.

This works:

3 Likes

Yes , certainly it works
But as you know if we have pictures with different formats or if we wanna use dynamic_named pictures, we cant use this algorithm
In fact your algorithm is correct ,
And my algorithm is correct too

That’s why the developer needs to plan appropriate names for images in advance.

exactly

then you need to save all picture name into a list, and use the SELECT LIST ITEM block, rather than so many IF THEN ELSE IF

Just create a dictionary like keys are numbers values are the image names.

Upon clicking, select a random integer for number and for image just use get value for the key (random integer) very simple

Similarly, it can be adapted for other Game of Chance, as

Because, if-elif-else would be tedious, if the game is to Pick a Card randomly from dack of 52 Cards.

You could also use this to draw the dice image locally (canvas is 100px x 100px).

The part before the "if-else"es draw the outline of the dice, while the 'if-else"es draw the dots by determining the number, e.g. if it is odd or even, or if it is larger by 3.

3 Likes

Thanks you all

Yes it's correct, but a tutorial must teach good and light programming

3 Likes