# Alternative (beginner) way to write this code?

**URL:** <https://discourse.processing.org/t/alternative-beginner-way-to-write-this-code/25298>\
**Category:** Processing.py\
**Created:** [November 9, 2020, 3:36pm UTC](https://discourse.processing.org/t/alternative-beginner-way-to-write-this-code/25298 "2020-11-09T15:36:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![millionish](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@millionish](https://discourse.processing.org/u/millionish)\
**Post date:** [November 9, 2020, 3:36pm UTC](https://discourse.processing.org/t/alternative-beginner-way-to-write-this-code/25298/1 "2020-11-09T15:36:39Z")

</div>

How do I write the code (below) in an alternative (beginner) way? I don’t wish to use createShape, setFill and addChild. Instead, any other way to perform the same thing?

```auto
grid = createShape(GROUP)
for i in range(C*R):
    self.cell = createShape(RECT, (i%C)*S, (i//C)*S, S, S)
    self.cell.setFill(colors[i] if i in filled else 210)
    grid.addChild(self.cell)

```

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 9, 2020, 8:43pm UTC](https://discourse.processing.org/t/alternative-beginner-way-to-write-this-code/25298/2 "2020-11-09T20:43:38Z")

</div>

Hi @millionish,

I’m sorry you couldn’t make use of the `createShape()` function. I can try to find another way but would you mind first explaining what **exactly** is the problem (1D coordinates or the shape making?) and what you are trying to do ?

This snippet alone doesn’t reveal much about your intention so it would help that you post the whole code or at least the related parts (I see a `self` so the corresponding `class` object would be nice for example)

Really, do not hesitate to share extra details, thoughts or questions. Also it would be appreciated that you keep your questions and code posted for clarity (avoid removing/deleting them) and out of respect for future readers who might have similar issues.

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 10, 2020, 9:58am UTC](https://discourse.processing.org/t/alternative-beginner-way-to-write-this-code/25298/4 "2020-11-10T09:58:40Z")

</div>

Again, please post the full code.

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 10, 2020, 10:25am UTC](https://discourse.processing.org/t/alternative-beginner-way-to-write-this-code/25298/6 "2020-11-10T10:25:41Z")

</div>

Thank you.

It seems you forgot a parenthesis `()` after `game.Grid` in `draw()`.

---

<div class="post-metadata">

**Author:** ![millionish](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@millionish](https://discourse.processing.org/u/millionish)\
**Post date:** [November 10, 2020, 10:32am UTC](https://discourse.processing.org/t/alternative-beginner-way-to-write-this-code/25298/7 "2020-11-10T10:32:25Z")

</div>

omg!!! I feel so stupid lol… Thanks anyways 🙂

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 10, 2020, 10:36am UTC](https://discourse.processing.org/t/alternative-beginner-way-to-write-this-code/25298/8 "2020-11-10T10:36:49Z")

</div>

No problem, typos happen a lot when writing code.
