Godot 4 Multiplayer: Make Your Own Online Game

I am not sure what I am missing here.

Whatever this error is, I was not able to save my progress.


Hi,

Where is the spawn_points variable declared, is it at top of script somewhere?

Normally that error, when I’ve seen it in the past, is that it’s trying to save the scene/script if the game is still running in the background and not stopped in the editor.

2 Likes

I think it is at the top.

I’m pretty sure OboShape is right about the project still running. “Unable to write file” usually means the file is in use.

Now that we can see where you declared the variable, your original error is because you declared it as _spawn_points instead of spawn_points (leading underscore). When you see “not declared in the current scope,” the first thing you should look for is a typo in your variable name, because 99% of the time, that’s what causes that particular error =)

2 Likes

Perfect! Thank you!

One day I will spot it without help. LOL

2 Likes

I fixed one error on my own.

I got another one. I tried this new one and cannot figure this one out.

This error happens after I START to play game.

:+1:

Making progress then! Ok.

  • Invalid
  • get index
  • ‘0’
  • on an array belonging to a Node2D (your level_01 object)

means the array has no value at that index - the program tried to return something that doesn’t exist (I broke that down into bullets because that’s how you go about reading an error statement. You won’t always be able to understand these errors because occasionally they’re downright cryptic, but this approach helps a lot).

If this is happening on index 0, it usually means the array is empty unless you have a good reason to skip indeces when giving it values. Whenever an array is unexpectedly empty, understandably you should check anywhere the array is being populated with data. Since spawn_points is an export variable, you should also check the inspector of this node to see if the field has been filled properly (and it may very well not be, as you renamed this variable by removing the leading underscore).

Invalid get index is a very common error, and it’s almost certainly going to be caused by one of these two things. Let us know what you find.

1 Like

Thank you.

Not quite sure I am following fully. I am sort of getting it.

I just checked and I don’t know where to make the edit.

Well, the error is resulting from trying to get the value of the array spawn_points at array index 0, which is at the beginning of the array. It can’t get that value because it’s discovering that it doesn’t exist - there’s no value there to get, and this is because you are expecting the array to have some data in it, but it doesn’t for whatever reason. Therefore the program throws an error.

It might be that you can’t find anything because you’re only looking in the level_01 script, but remember that spawn_points is an export variable, so the data it gets filled with is coming from somewhere else. In addition to level_01, check wherever spawn_points is coming from, and also double-check that the field is filled (because if it’s empty, that’s your problem).

If you’re completely at a loss, try Ctrl + Shift + F and search for spawn_points (this feature is called “Find In Files” btw, and it’s very useful). This will show you every place it appears across ALL your scripts.

1 Like

Thank you for your help! I used the search and found the spawn_points. Just need to figure out how to make the change. I will watch the video again.


The instructor typed in 0.

Since Find In Files searches through all scripts, and none of the results indicate that there is code setting spawn_points to some value, and we can see that spawn_points is an @export variable, this can only mean that values are entered directly in the inspector (unless of course those values come directly from another array like the Polygon in Kaan’s Speedy Saucer game, which I don’t think is going to be the case here). I would indeed see if you can find the video where spawn_points is given values.

Edit: Spawning Players, 12:30 to the end. This is where spawn_points is populated, so by all means watch it again. That’s the nice thing about video courses - you can watch and rewatch as much as you need to.

2 Likes

OK. I will definitely watch it again.

Thank you!

Got it! (I think)


1 Like

Hi. New issue.

When I paly the game to test it, the player steps on plate and the game shuts down or stops and the script window with error is shown.

Another thing I noticed in the Replication window, the instructor has different options. I don’t have. Not sure if that is causing any issues for me.

I made the correction the instructor mentions later in the same lecture. I synched the MultiplayerSynchronizer to the Delta Synchronizer.




My Replication window

Instructor’s Replication window

Any time you see an error message, I would recommend that the first thing you do is read it very closely. Skimming is not enough; look at it word by word with a figurative microscope. The reason for that is, sometimes that’s all you need to do.

Do that with this one. Can you spot the issue? I will tell you if not, so don’t panic, but this is good practice =)

I can’t help with the other part unfortunately, but I suspect it’s a similar issue to your missing @export variables a few weeks ago, so all I can suggest is to watch the lectures again and look for anything you might have missed.

1 Like

Hi, I appreciate the challenge. I am going to give it a shot now.

Thank you!

A typing error again. OMG!

It works now. Thank you!

I am trying like heck! Maybe I am trying too hard. SMH

Remember when you said “Someday I’ll find it without help”?

Looks like “Someday” came.

Personally, I think it’s less that you’re trying too hard and more that you would benefit from boosting some foundational skills.

Coding is one thing, but navigating your way through the inevitable bugs and errors that come from coding is a whole different beast. Even when I was taking programming courses in school, very few other students actually had a solid grasp of debugging strategies, and that’s because there was comparatively almost no instruction in it at all (not the professors’ faults, but that’s another matter).

This is a pretty good start (not all of the article is relevant; I recommend reading from “How to Debug your Code” to down to “Write simple code when possible”). Check this out when you get a chance, and then, the next time you run into a problem, read through this again and try some of what’s in there:

1 Like

Yes, I certainly did. Thank you! I understand what you mean.

Thank you for the resource!

1 Like

Privacy & Terms