Continuing to mess around with the Random exercise, I am now trying to implement the last task: show the dice rolling a random number of times before settling down to the final result.
I’m having trouble figuring out how to build such a thing without loops x_x
Also, the fact that I can’t just generate a number in a function, but I need 1 function to set the generator rules and a second one to use a command to produce the number… is confusing.
My idea is simply to call the die-roll function multiple times.
But in terms of actual logic and code it’s resulting very tough for me.
I add a new type of Msg
| NewFace Int
Then I think I should add a new case to the Update function, but given the expected structure it’s unclear to me HOW I am supposed to do it
In my mind I need to create a random number, to be used as the number of times the die needs to roll.
But this already is a problem as it should be something like…
Random.generate Cmd rollRules
The Cmd part is the problem… what is it? What am I supposed to create to make it work?
In the example/tutorial this fat that Cmd was simply a Type (the NewFace one).
So… what… I create a Repeat thing?
| NewFace Int
**| Repeat Int**
So I write a function that uses these pieces to generate my new random number…
Random.generate Repeat rollRules
This sends the update case function into a panic, because not all cases are covered.
So I add a new case…
This is not good, as the case is a Cmd Msg while the rest of the cases are (Model, Cmd Msg).
I can fix this by writing the case like this:
But why? I don’t need the model in here!
Anyway, this produces a different problem, as the Repeat case is not taken care of.
And here I basically get totally lost