#For Loop goes faster

35 messages · Page 1 of 1 (latest)

fringe tendon
#

I'm not sure what you're saying

#

Specifically, what is the for loop faster than???

ember smelt
#

When there are multiple elements in an array, it updates faster, as seen by the example Gifs.

fringe tendon
#

Your code doesn't really tell me enough to say exactly what's happening. But with 10 items in the array you're gonna call update 10 times, if there's only 1 item you only call update once.

ember smelt
#

Yeah, and is there anyway to seperately update each one?

fringe tendon
#

No idea. You would need to share more code.

ember smelt
#

ah my bad

#

What code do you need?

fringe tendon
#

No idea. It's your code and I haven't seen it.

ember smelt
#

It's really just the W3School Flappy Bird example code.

fringe tendon
#

No idea what that is or where to find it.

ember smelt
#

It is that one

fringe tendon
#

I don't see why any of that code would be sped up by adding more components. It already adds new components over and over.

ember smelt
#

The loop that I've underlined is the one that I used

fringe tendon
#

Did you change anything else?

ember smelt
#

When I got rid of myObstacles[i].x += -1;, it started going faster

#

forgot to mention, I have my own moving part, but that's not what is making it faster.

#

I debugged it, and it is the for loop that is making it faster

fringe tendon
#

What else did you change?

ember smelt
#

I believe that's it

fringe tendon
#

So the gifs are the result of changing that one line?

ember smelt
#

I got rid of the line, I have my seperate moving system, but what I believe the problem is that it is being updated faster.

#

So my question is if there is any way to slow them down

fringe tendon
#

Ok, so you did change stuff. I can get rid of that one line too and nothing goes faster.

#

So some other change you made is causing things to go faster when you remove that one line.

ember smelt
#

The line makes it move by itself, however that's not what I want anyway.

fringe tendon
#

Makes what move by itself?

ember smelt
#

The line makes the component move by itself, my code makes it so you choose where it goes, that is not the problem though, I debugged the code manually and found out that the for loop is the problem.

fringe tendon
#

The components are the green lines in the W3C code. You don't have the green lines so I'm not sure what's moving by itself.

Again, removing that line from the W3C code doesn't result in a speed up for me. Therefore some other change you made must be causing the speed up when that line is removed.

ember smelt
#

man, forget about it, i'll just try myself

#

thanks for the help

fringe tendon
#

Sorry. I can't help if I can't replicate the issue. No one would be able to help you given the information you have shared thus far.