Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array stopping #7

Open
AlexPitre opened this issue Sep 21, 2017 · 4 comments
Open

array stopping #7

AlexPitre opened this issue Sep 21, 2017 · 4 comments

Comments

@AlexPitre
Copy link

once my array cycles through, the program stops.

How can I get it to start back at the beginning?

I'm struggling with a few things, but one at a time I guess. All the // stuff is another issue.
https://alpha.editor.p5js.org/a.pitre/sketches/rkPxaaT9Z

@chjno
Copy link
Owner

chjno commented Sep 21, 2017

aw you're so close! take a look at what you're measuring the length of right now and think about what you're trying to measure the length of. lmk if you still can't figure it out.

if (index > index.length - 1){
  index=0;
}

@AlexPitre
Copy link
Author

ok, so i knew it was in that line. and i've tried a few different things and moved the if statement around. and just retried them.

i'm understanding it as:
when the index is at the last position, the index becomes position 0 again. but that isnt happening and when i change the increment in if statement, it doesn't really change anything and if i take the line out completely it still runs the same.

@chjno
Copy link
Owner

chjno commented Sep 21, 2017

Your index variable is a number, and the .length method only works for arrays (as far as we've seen... it actually works for strings, too). You want to be comparing index to the length of the burn array instead of the length of itself, so it should read:

if (index > burn.length - 1){
  index=0;
}

@AlexPitre
Copy link
Author

ah ha! i had it wrong in my notes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants