Hi everyone. Total newb to the godot engine here and working my way through the very first demo project in the main docs (the first 2d game). Surprisingly, despite feeling relatively confident I’ve followed every line exactly, I cant get the code to run after adding the code for the Main (game) node. (this step: The main game scene — Godot Engine (stable) documentation in English)
Long story short for those who might not recall, the tutorial has you start by making a Player scene to respresent the player, an Mob scene to represent the enemies, then finally you make a Main scene, which you then add code to instantiate some mobs and do stuff with the player. Also, you manually add one instance of Player to the tree under Main inside the engine.
But, after adding in the code in Main to instantiate instances of and manipulate these scenes, I get:
CS0246: The type or namespace name ‘Player’ could not be found (are you missing a using directive or an assembly reference?)
CS0246: The type or namespace name ‘Player’ could not be found (are you missing a using directive or an assembly reference?)
Did I somehow miss a line somewhere in the tutorial or is it actually possible this is somehow an oversight in the very first tutorial? xD
PS As an aside, ive never used an open source community semi indie feeling type tool like Godot extensively before. Surprisingly Im thinking there might be a few things that need to be added to that very first tutorial (though i could be wrong) where the project is messed up when simply following line by line. For example, i also seem to have to correct the code every time i click connect on a signal because it always adds the function code into the code file outside of the main {} braces. Im wondering, is the experience im having starting out relatively normal and should i expect a fair number of rough edges or…? I’m definitely hopeful to make this the main engine i use from now on but like I said ive never gotten involved in a big open source project before so im wondering if i should already be thinking of and finding out how to suggest problem spots in the very first tutorial.
Without seeing exactly what you’ve typed its impossible to distinguish between tutorial error and code transfer error. My base instinct is that you might be declaring the player and mob incorrectly.
pay attention to uppercase and lower case, im sure the tutorial wrote mob in all lower case
as for the Player, did you forget to add dollar-sign before it?
Hi all, thank you for the comments. So, as for the code, Its basically just the tutorial code copied and pasted from that first tutorial page. So, for example the code snippet:
Mob mob = MobScene.Instantiate<Mob>();
// Choose a random location on Path2D.
var mobSpawnLocation = GetNode<PathFollow2D>("MobPath/MobSpawnLocation");
mobSpawnLocation.ProgressRatio = GD.Randf();
// Set the mob's direction perpendicular to the path direction.
float direction = mobSpawnLocation.Rotation + Mathf.Pi / 2;
// Set the mob's position to a random location.
mob.Position = mobSpawnLocation.Position;
// Add some randomness to the direction.
direction += (float)GD.RandRange(-Mathf.Pi / 4, Mathf.Pi / 4);
mob.Rotation = direction;
// Choose the velocity.
var velocity = new Vector2((float)GD.RandRange(150.0, 250.0), 0);
mob.LinearVelocity = velocity.Rotated(direction);
// Spawn the mob by adding it to the Main scene.
AddChild(mob);
Contains the line trying to instantiate a Mob、And the snippet:
_score = 0;
var player = GetNode<Player>("Player");
var startPosition = GetNode<Marker2D>("StartPosition");
player.Start(startPosition.Position);
GetNode<Timer>("StartTimer").Start();
Tries to refer to a Player. Again, both are simply basic scenes that were made earlier in the tutorial (And in the case of player, was successfully tested and used)
You figured it out. Thank you very much Yep i think you were absolutely spot on in your original reply. The top parts of the code for both were:
public partial class mob : RigidBody2D
and
public partial class player : Area2D
I changed both to uppercase and viola.
Thank you so much you are amazing!! xD
And then finally, id love to just hear a quick opinion like
id have to check to be 100% certain but i think its like you said and i think these lines were auto generated by the engine (i think maybe its when you create them, it is autopopulated as lowercase in the file selector maybe. i actually went back and changed the file names to upper case but then these were left lower case i guess, which also iirc other IDEs auto update this but i could be wrong). Similarly, when following the tutorial im pretty sure every time i hooked up a signal it autogenerated the code outside the main {} of the class leading to compile errors that i had to fixed, also not discussed or mentioned in the tutorial im pretty sure. Would you say the engine in general is a little rough around the edges in this way and one should reasonably expect to get stopped by lots of little rough around the edges things like this given the open source and nascent nature of the engine?
Should i already be finding out or investigating about trying to recommend or suggest or do myself changes to the tutorial to warn people about these things and how to fix them? Does it seem like im just dumb or something? I would think a lot of beginners would get tripped up when these things exist in the very first official documentation tutorial…right?
i do believe that godot game is meant to be written in GDScript code, other extensions like C# functionality may need improvement for their built-in editor, but i don’t really used C# to write code in godot. AFAIK, people would use Microsoft Visual Studio or Code to write codes for c# language, not by using the Built-in Godot editor.
i checked the documentation tutorial, it does have the Mob to be uppercase
but i cant find the full player script