# Making multiple lanes using arrays

**URL:** <https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161>\
**Category:** Beginners\
**Created:** [May 28, 2022, 11:13am UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161 "2022-05-28T11:13:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 11:13am UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/1 "2022-05-28T11:13:18Z")

</div>

Hi ! I am having issues trying to make multiple lanes for a project. I have made one lane using a loop as it is a dashed lane. I am struggling to make multiple of those lanes in my game using an array. Can someone please help me?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 11:33am UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/2 "2022-05-28T11:33:10Z")

</div>

You have one for loop now for the dashed line

The line is at a certain y and leading to the right

* * *

Now surrounded the entire for loop (from for to } )  
with a 2nd outer for loop that tells you how many lines you want to have underneath each other.

The array could represent the y values for the lines.

So before setup make the array

int[] listY = {  
103,  
160,  
230

};

outer for loop

```auto
for(int index = 0; index<3; index ++) {
   for (...
     line(..., listY[index], ...., listY[index]);
   }
}

```

fill in the blank

---

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 12:29pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/3 "2022-05-28T12:29:14Z")

</div>

![Screen Shot 2022-05-28 at 10.28.48 pm](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/0/c/0cd58f6d0e98ec6beb1ebac6eb98e3ff5b8d2378.png)

I am getting some sort of error.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 12:58pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/4 "2022-05-28T12:58:15Z")

</div>

Check your brackets{}

No code allowed outside the functions like draw

Remember to use ctrl-t to get auto indent

You only will get real help when posting your code as text

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 1:00pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/5 "2022-05-28T13:00:05Z")

</div>

Presumably after the for loops have 2 instead of 3 }

---

<div class="post-metadata">

**Author:** ![yug717](https://avatars.discourse-cdn.com/v4/letter/y/f475e1/32.png) [@yug717](https://discourse.processing.org/u/yug717)\
**Post date:** [May 28, 2022, 1:24pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/6 "2022-05-28T13:24:19Z")

</div>

I did some coding for that according to what you said but my lanes have disappeared.

Here is my coding:

\<  
void draw() {  
//dashed horizontal line  
background(255);

for(int index = 0; index\<3; index ++) {  
for(varx=0; varx\<=width;varx = varx + 40);  
line(varx, height/4, varx+30, height/4);  
}

>

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 1:45pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/7 "2022-05-28T13:45:15Z")

</div>

> [@yug717](#):
>
> varx = varx + 40);  
> line

No semicolon here

It closes the for loop

---

<div class="post-metadata">

**Author:** ![yug717](https://avatars.discourse-cdn.com/v4/letter/y/f475e1/32.png) [@yug717](https://discourse.processing.org/u/yug717)\
**Post date:** [May 28, 2022, 1:47pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/8 "2022-05-28T13:47:46Z")

</div>

I removed the semicolon. I still do not see multiple lanes. It is back to the one lane.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 1:48pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/9 "2022-05-28T13:48:35Z")

</div>

Show me the code

Chrisir

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 1:49pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/10 "2022-05-28T13:49:33Z")

</div>

You also removed { } around the inner for loop

Why?

---

<div class="post-metadata">

**Author:** ![yug717](https://avatars.discourse-cdn.com/v4/letter/y/f475e1/32.png) [@yug717](https://discourse.processing.org/u/yug717)\
**Post date:** [May 28, 2022, 1:52pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/11 "2022-05-28T13:52:10Z")

</div>

because it said unexpected token.

\<

void draw() {  
//dashed horizontal line  
background(255);

for(int index = 0; index\<3; index ++) {  
for(varx=0; varx\<=width;varx = varx + 40)  
line(varx, height/4, varx+30, height/4);  
}

>

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 1:53pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/12 "2022-05-28T13:53:50Z")

</div>

> [@yug717](#):
>
> for(int index = 0; index\<3; index ++) {  
> for(varx=0; varx\<=width;varx = varx + 40)  
> line(varx, height/4, varx+30, height/4);  
> }

```auto
for(int index = 0; index<3; index ++) {
for(varx=0; varx<=width;varx = varx + 40) {
stroke(0);
line(varx, height/4, varx+30, height/4);
}
}

```

---

<div class="post-metadata">

**Author:** ![yug717](https://avatars.discourse-cdn.com/v4/letter/y/f475e1/32.png) [@yug717](https://discourse.processing.org/u/yug717)\
**Post date:** [May 28, 2022, 2:01pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/13 "2022-05-28T14:01:18Z")

</div>

i still do not see multiple lanes. Maybe the error is in the array making.  
\<

// Array

int listY = {  
103,  
160,  
230

};

> 

This array code is before set up

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 2:02pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/14 "2022-05-28T14:02:23Z")

</div>

You don’t use the array

Please see the way I did it

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 2:03pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/15 "2022-05-28T14:03:46Z")

</div>

The 2 for loops are in draw, right? After background?

In the section where showGameOverScreen is false amd you set the variable to false before setup ()?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 2:05pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/16 "2022-05-28T14:05:01Z")

</div>

> [@Chrisir](#):
>
> `height/4`

Of course since you always use this instead of the array the 3 lines are on top of each other

Same y values for all

Instead use array as shown

> [@Chrisir](#):
>
> `listY[index]`

Like here please

Thank you!

Chrisir

---

<div class="post-metadata">

**Author:** ![yug717](https://avatars.discourse-cdn.com/v4/letter/y/f475e1/32.png) [@yug717](https://discourse.processing.org/u/yug717)\
**Post date:** [May 28, 2022, 2:10pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/17 "2022-05-28T14:10:03Z")

</div>

I still don’t understand what you mean. When i change the value of heigth/a no., it changes the shape of the dash and makes it diagonal. I’m so sorry it is taking me a while to understand.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 2:10pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/18 "2022-05-28T14:10:57Z")

</div>

> [@Chrisir](#):
>
> `line(varx, height/4, varx+30, height/4);`

Replace height/4 in both places with the array

listY[index]

---

<div class="post-metadata">

**Author:** ![yug717](https://avatars.discourse-cdn.com/v4/letter/y/f475e1/32.png) [@yug717](https://discourse.processing.org/u/yug717)\
**Post date:** [May 28, 2022, 2:13pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/19 "2022-05-28T14:13:40Z")

</div>

oh okay and how do we change the number of lanes we want? For example when we substitue 10 in the following for 4, it should change to 4 lanes:

\<

final int N\_CARS\_IN\_LANE = 10;

>

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 2:25pm UTC](https://discourse.processing.org/t/making-multiple-lanes-using-arrays/37161/20 "2022-05-28T14:25:46Z")

</div>

> [@Chrisir](#):
>
> ```auto
> for(int index = 0; index<3; index ++) {
> 
> ```

In this line please

Chrisir
