pllambrecht

unread,
Jan 4, 2019, 5:24:09 PM1/4/19
to MIT App Inventor Forum
I am creating a dice roller for Shadowrun V5 and was looking for some help on how to make my blocks more elegant.

Attached is a screenshot of the current app and the blocks associated with it.

Right now it works the way I want it, but instead of 6 functioning dice, there will be 30 or 36. You can see that if I scale it up from the current way of doing it, it will be quite unwieldy.

Here is the current and expected functionality:

1. The user clicks on the dice. If they are only rolling 3 dice, they click on the third dice. If they are rolling 6, then the 6th dice, 20 then the 20th, etc.
2. Clicking on a dice initially resets everything: variables, background images.
3. Based on the generated random number, the background of each button is changed to match that number.
4. Glitches and Critical Glitches are calculated and displayed.

I'm sure that there is some logic that can handle a mass amount of dice (like a "for each"), but I am currently unable to wrap my head around it.

Any help would be greatly appreciated. Thanks.
blocks.jpg

TimAI2

unread,
Jan 4, 2019, 6:13:01 PM1/4/19
to MIT App Inventor Forum
Yes, after just a quick review of your blocks:

  1. You can make a list of all your die buttons and then iterate over these using the any component blocks for screen initialise and reset
  2. Because you have a sensible naming strategy - r1c1 | r1c2 etc, you should be able to make one procedure with inputs to handle the rolls
  3. Not much you can do about the button click events, you have to have one for each button used
Don't have time now to put an example together, someone else might, or I may have time tomorrow.

pllambrecht

unread,
Jan 5, 2019, 8:13:22 AM1/5/19
to MIT App Inventor Forum
Thanks for the reply and helpful input!

I was able to figure out the list and "any component" part fairly easily. That makes life a lot easier.

Still trying to figure out the procedure to roll the dice. Yes, the naming strategy is set up by row/column.

Where I am having issues is limiting how many dice are rolled. so if I click on button 8 it only rolls r1c1 through r2c2.

TimAI2

unread,
Jan 5, 2019, 8:47:47 AM1/5/19
to MIT App Inventor Forum
I attach an example aia that may help

Makes extensive use of the any component blocks and provides some universal procedures
This should,  I hope, help you along ?
rolldice.aia

pllambrecht

unread,
Jan 8, 2019, 10:54:56 AM1/8/19
to MIT App Inventor Forum
This is great! 

I have gone in and upped the number of dice to 30, changed it a bit so that the default non-rolled dice use the same background, and some other things.

The next step is figuring out how to do edge-point re-rolls (re-rolling the 2's, 3's, and 4's) as well as throwing in the Rule of 6 (rolling an extra die for each 6 rolled).

Thanks so much for your help!

TimAI2

unread,
Jan 8, 2019, 11:08:29 AM1/8/19
to MIT App Inventor Forum
Nothing like a challenge!

Look forward to seeing the result :)

pllambrecht

unread,
Jan 8, 2019, 11:42:24 AM1/8/19
to MIT App Inventor Forum
One other question I have concerns the pause between pushing a button and displaying the results. I assume that is because of the clock/timer.

Is there any way to speed that up?

TimAI2

unread,
Jan 8, 2019, 1:07:04 PM1/8/19
to MIT App Inventor Forum
Yes, you can reduce the timer interval. In my example I left what i thought was long enough for the user to see the dice reset to 123456, then do the roll based upon the die click.
If you speed it up too much this may happen so fast you don't see it, however with the notifier it does tell the user that they have rolled the dice.
Reply all
Reply to author
Forward
0 new messages