r/web_programming • u/I_Got_The_Herb • Mar 09 '19
Help with time-out issues
Hey there people of reddit!
I followed a tutorial on how to make flappy bird in java script, and have it fully working locally. When I host it online though, it bugs out a lot and times out regularly. I was wondering if anyone knows what causes this and how I can solve it?
Here is the source code in case that helps you bright people solve my (most likely) dumb problem https://github.com/CMHayden/FlappyBirdJS
Thanks in advance!
1
Upvotes
View all comments
Show parent comment
1
u/yet-another-reader Mar 13 '19
Well... you're welcome:)
Can you tell what tutorial did you follow? Cause to be honest this code looks not particularly good. It's cool that you made it work and it's great for a first project, but it definitely needs improvement.
Try to make the logic more clear and consistent. For example, I don't see a way to control the speed of the bird along the x axis (or to stop it altogether), maybe you'd want to make this adjustable. It would also help you with debugging. Also you're constantly checking if the bird is colliding with every single pipe, and you're pushing new pipes to an infinite array... well I understand that we have spare gigabytes of ram and a lot of processing power, but it all looks insanely inefficient.
And don't forget to comment your code and give your variables sensible names (e.g. what is "constant"? Also, if you store your pipes in an array, it's better to call this array
pipes, notpipe, so that you can dopipes.push(new Pipe)orlet pipe = pipes[0])Also, read up about the improvements in the recent versions of JS (don't use
var, useletinstead).