How overwrite func in custom global classes an use this first method?

Godot Version

4.5

Question

In the state class, I have a function on_ready(), and when I try to call it for lessons on YouTube, I get this error:

Error at (8, 5): Expected statement, found "." instead.

This is the code:

extends State
class_name EntityState

var entity : Entity

func on_ready() -> void:
	entity = state_tree.get_parent()
	.on_ready()

I assume you mean to call this class’ on_ready function elsewhere. You must have a variable or function before using dot . methods.

Make sure to give more context, maybe link the video you are using, explain what you are trying to make and why you are stuck.

Seems like you are making a state machine? Maybe the video wants you call on_ready from the state machine, like current_state.on_ready(), such as this transition function

extends Node
class_name StateMachine

var current_state: State
func transition(new_state: State) -> void:
    current_state.on_exit()
    current_state = new_state
    current_state.on_ready()
2 Likes

I downloaded the project from a video I watched, this method was relevant for version 3, but in the new version it looks like this:

We have: func stop() in BasicSlime class

extends RigidBody2D
class_name BasicSlime

func stop():
	sleeping = true

And we will inherit it for a new class.:

This will be the case for version 3:

extends BasicSlime
class_name Sniper

func stop():
	body.play("idle")
	.stop()

This will be the case for version 4:

extends BasicSlime
class_name Sniper

func stop():
	body.play("idle")
	super.stop()

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