# Trying to get my head around commands

**URL:** <https://discourse.elm-lang.org/t/trying-to-get-my-head-around-commands/9586>\
**Category:** Learn\
**Created:** [January 14, 2024, 1:55pm UTC](https://discourse.elm-lang.org/t/trying-to-get-my-head-around-commands/9586 "2024-01-14T13:55:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlotm](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/carlotm/32/4785_2.png) [@carlotm](https://discourse.elm-lang.org/u/carlotm)\
**Post date:** [January 14, 2024, 1:55pm UTC](https://discourse.elm-lang.org/t/trying-to-get-my-head-around-commands/9586/1 "2024-01-14T13:55:48Z")

</div>

Greetings,

I wrote a small app while learning Elm.

When the user clicks the “Add shadow” button, [1] a new shadow is appended to the list of shadows, and [2] I would like to randomly generate a color for it.

Right now, I am able to append a new shadow to the list [1] and generate a random color [2] independently. I can’t figure out how to make it work togheter.

The code is way better at explaining my issue than my words:

> **[GitHub - carlotm/umbra: A multi box-shadow generator](https://github.com/carlotm/umbra)**
>
> A multi box-shadow generator. Contribute to carlotm/umbra development by creating an account on GitHub.

I would like to replace the `#000000` at [this line](https://github.com/carlotm/umbra/blob/main/src/Umbra.elm#L438) with a randomly generated color (the code to generate the color is in the same file)

Thank you

---

<div class="post-metadata">

**Author:** ![wolfadex](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/wolfadex/32/2461_2.png) [@wolfadex](https://discourse.elm-lang.org/u/wolfadex)\
**Post date:** [January 14, 2024, 2:09pm UTC](https://discourse.elm-lang.org/t/trying-to-get-my-head-around-commands/9586/2 "2024-01-14T14:09:47Z")

</div>

If I understand correctly, you want to generate the color in the same step as the shadow is added?

If so, you’ll want to use `Ranrom.step`, which will require you to store a `Random.Seed` in your model.

---

<div class="post-metadata">

**Author:** ![carlotm](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/carlotm/32/4785_2.png) [@carlotm](https://discourse.elm-lang.org/u/carlotm)\
**Post date:** [January 14, 2024, 2:14pm UTC](https://discourse.elm-lang.org/t/trying-to-get-my-head-around-commands/9586/3 "2024-01-14T14:14:32Z")

</div>

> [@wolfadex](#):
>
> If I understand correctly, you want to generate the color in the same step as the shadow is added?

Exactly.

I’ll look into Random.step, thanks.

---

<div class="post-metadata">

**Author:** ![carlotm](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/carlotm/32/4785_2.png) [@carlotm](https://discourse.elm-lang.org/u/carlotm)\
**Post date:** [January 14, 2024, 2:45pm UTC](https://discourse.elm-lang.org/t/trying-to-get-my-head-around-commands/9586/4 "2024-01-14T14:45:43Z")

</div>

I’ve found a simpler solution.  
When the “Add a shadow” button is clicked, I run the command to generate a color,  
when the color has been generated, I actually add the shadow with the generated color.

In code:

> <https://github.com/carlotm/umbra/commit/e5a4ca1de7a8418c1f301133ecc3ed13e3d1aec2>

---

<div class="post-metadata">

**Author:** ![dwayne](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dwayne/32/5478_2.png) [@dwayne](https://discourse.elm-lang.org/u/dwayne)\
**Post date:** [January 15, 2024, 1:14am UTC](https://discourse.elm-lang.org/t/trying-to-get-my-head-around-commands/9586/5 "2024-01-15T01:14:05Z")

</div>

@carlotm Your project has introduced me to [Devbox](https://www.jetpack.io/devbox/). Thanks! I currently use Nix flakes but Devbox seems to be more user friendly and also built upon Nix.

BTW, feel free to submit your app to [Built with Elm](https://www.builtwithelm.co/).

---

<div class="post-metadata">

**Author:** ![carlotm](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/carlotm/32/4785_2.png) [@carlotm](https://discourse.elm-lang.org/u/carlotm)\
**Post date:** [January 15, 2024, 6:28am UTC](https://discourse.elm-lang.org/t/trying-to-get-my-head-around-commands/9586/6 "2024-01-15T06:28:16Z")

</div>

> [@dwayne](#):
>
> Devbox seems to be more user friendly and also built upon Nix.

Yeah, it’s a lovely tool.  
With the limitations of json, but lovely 🙂

Cheers!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [January 25, 2024, 6:28am UTC](https://discourse.elm-lang.org/t/trying-to-get-my-head-around-commands/9586/7 "2024-01-25T06:28:42Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
