Invalid Call in 'your first 2D game tutorial'

Godot Version

4.2

Question

Very new to programming, so please forgive me, I couldn’t find an answer on Bing.
I had made the player scene work; but now that I’m done with the main node scene, when attempting to run the project (f5) from the main node, it closes immediately and gives me this in the debugger:

Invalid call. Nonexistent function ‘start’ in base ‘Area2D (player.tscn::GDScript_yt17y)’.

So far I have tried:

  • closing and re-opening Godot
  • confirming the node-nesting order for the main scene
  • the program boots Main.tscn from the project settings
  • the script is attached to the player node
  • copy/paste the exact code from the tutorial in godotengine.org

below is the code, pasted from the main.gd

extends Node

@export var mob_scene: PackedScene
var score

Called when the node enters the scene tree for the first time.

func _ready():
new_game()

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta):
pass

func game_over():
$ScoreTimer.stop()
$MobTimer.stop()
func new_game():
$Player.start($StartPosition.position)
$StartTimer.start()

func _on_mob_timer_timeout():
#Create a new instance of the Mob Scene
var mob = mob_scene.instantiate()

#random start point on Path2D node
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress_ratio = randf()

#set the mob's direction perpendicular to the path direction.
var direction = mob_spawn_location + PI / 2
#set the mob's position to a random location
mob.position = mob_spawn_location.position 
#pick random direction
direction += randf_range (-PI / 4, PI / 4)
mob.rotation = direction

#pick random velocity for mob
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)

#actually produce the mob
add_child(mob)

func _on_score_timer_timeout():
score =+ 1

func _on_start_timer_timeout():
$MobTimer.start()
$ScoreTimer.start()

The error tells you that you are trying to call the start function on an Area2D but the area2d doesn’t have a start function. I think your $StartTimer may be an Area2D instead of a timer. Can you link to the tutorial you followed?

Although, the error points to a script in player.tscn. Do you have a built-in script in your player scene?

Try editing your post, selecting all the code, and then pressing the little </> button at the top of the post editor. That should make sure that your code is shown with syntax highlighting and indentation.

1 Like

if you share screenshot of your node tree and code I think I can figure it out what actually going wrong in code. but general looking of your seems like you are trying to call a functions that does not exists.

Snipercup,
I believe I do, the tutorial had you build the player scene and attach the script to it first, before moving on the the mob scene (enemy scene). So i have the script icon at the very least.

In the attached image it should show a timer icon for the $StartTimer node. But I will check the tooltip again when I have the chance.

Here is the link to the tutorial:

Sunna, attached should be a screencap

Did you add the start function to your player script?

func start(pos):
	position = pos
	show()
	$CollisionShape2D.disabled = false

As described at the bottom of this page.

2 Likes

tay, thanks so much, that one was the ticket.

I left the ‘t’ off of the ‘start’ function, so when I called on it later, the code couldn’t find it, and It didn’t occur to me to go to where it was declared to check. Following that I had a couple of other issues of the exact same kind, but its all worked out.

As to why the copied code from git didn’t fix it? I only copied the main.tscn script, and never checked the player script at all, so future readers of this post be aware of that.

I obviously need to work on the fundamentals, thanks again everyone.

tldr;

miss typed the block on the player script
func start(pos):
never checked back on it when trying to call it from the main script.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.