Is it bad to ask for help a lot?

Hello! I’m currently making a game and I’m almost done but when I implement to automatic movement controls to the game, it seems to come out glitchy. I’m making the Nokia Snake game and I cannot figure out why this is occurring. I don’t know if I should ask for help and post my code or if that will be cheating but I’m not sure what to do. Thank you

You can’t get any better without asking for help. However at the time , you have to also study and learn beyond what your helpers give. And ideally learn from it.

Of course that is assuming the snake game isn’t some kind of assignment. If it is, you have to get permission from your teacher/boss/whatever first. Otherwise, you don’t have that much to worry about.

1 Like

Yeah, this is just a personal project but this is basically what I have right now and I just can effectively create automatic movement for all the player and the body pieces

I tried implementing set interval when you hit certain key directions but the output is that the body squares start to disappear, re apper, and pop in and out of the grid

Actually I think I have an idea I can try. I think if I’m using setInterval on key presses and only rendering when keys are being pressed, maybe the discrepancy lies in the non rendered movement when the keys aren’t being pressed, but the squares are still moving… it sounds weird but I’ll see if this works.

This is the code I’m referring to https://codepen.io/bbg4/pen/xxeBVOZ?editors=1010

I was able to kind of update it to where the movement will utilize one setinterval because i think having 5 of them was affecting the interval timing. I’m confused about why the code is executing two different directions at a time whenever you change key presses. I’m really confused about how setinterval works here. https://codepen.io/bbg4/pen/ZEZNzLm

I google, do research and all kinds of things before I ask a question for help but I still do. Its part of being a programmer. Good luck with your gaming project and completing it as well.

Thanks! it’s more that when I google information about a particular syntax it gets confusing like i think i understand how set interval works, but i don’t understand if this if statements in set interval is creating a new instance of set interval whenever the key is pressed, or if this is one set interval and the previous key press remain for some reason. It gets iffy like that and sometimes google doesnt answer it.

Yeah there is a work around for that it has to reset everytime you use it or the variable holds it thats where they use the term container. You right about google, you can link generative AI which is more accurate.

I would suggest below

  1. Google and go through all the search results on page 1

  2. Do some R&D yourself

  3. Even after step 1 & 2 ( you’ve given your 100% ), if you’re struck ( after 1 day ideally ) then ask for help, along with steps you have tried; what worked and what didn’t

This way others will get to know how much efforts did you put to solve that problem, also it’s good habit to flex your brain muscles first; before asking for help immediately.

Oh, okay.

So I will say that the steps i have tried include:

  1. Converting multiple set intervals for each player keycode to one giant set interval which allows me to move in different without multiple intervals being called.
  2. Fixed the interval timing issue which fixes a delay between key presses

I think the step I’m stuck on now is that the variable outside of set interval won’t stop itself when a new direction is pressed

So to reset it do you just set the variable that holds the keyCodes to 0 inside each if else keycode statement? I’m not sure what a container is either ngl. This concept is really new to me

The zero approach might work, but this is probably better, make an if and else if statment.

I did a Unity game dev course for about 3-6 months this issue came up in C# actually. If when assigning keys I rememmber this subject otherwise I wouldnt even know about it.
Once you figure out what to do you`ll use this information alot. You might try the drum machine project here on FCC and there is no requirment to go right to the project.

Make an if else statement hmm… Would it be something like if key code variable equals one of the conditional key presses to assign it to the key code, else the keycode variable equals 0?

I could not retrieve the info, it looks like you already have what copilot had but Im having a difficult time getting the link to work. But that said all they did there is make a bunch of long if and else statements as opposed to just some simply code like if(variable.value === 0) Are you still working on this I went to codepen, not sure if the project is working, I havent really tried yet.

I think the link might be broken

Personally I do not agree with this

I dont think it makes sense to wait this long if you are stuck to ask for help. It’s important to do the initial stuff yourself, but if it’s been an hour or two then ask for help. If you were in a professional setting, and had a task to get done your tram probably wouldn’t be happy you waited an entire day to ask for help because thats an entire day lost on progress

Ah okay gotcha. I actually did some research and it looks like javascript containers ar objects i think?

1 Like

Oh yeah i have the link to the project here.

Also I’m not sure if I should be using clearinterval in this case too or if resetting the variable is the right choice. This is what my code looked like originally before modifying to the posted version. https://codepen.io/bbg4/pen/xxeBVOZ
This version “worked”, but the snake would come out really laggy and the body blocks would phase in and out. I received help on that where someone said that the multiple set intervals and clearing intervals were creating a timing issue with the key executions. I’m not sure if I’m supposed to clear the interval in this case, or if there’s a better way to reset the variable. I know you said to use an object container , or special if else statements but i’m still unsure. I wish I could see that if else link to browse