how do you fix this code?

Godot Version

4.4

Question

`extends Area2D

var CharacterBody2D

func _on_CharacterBody2D_eneter_underworld():
if true: move_CharacterBody2D(x, 100, y 300)

on the if true it doesn’t work. could someone help

If what is true? If true means nothing.

Probably not, because of a few reasons:

  1. No description of what the code should do is provided.
  2. No description of what the code does instead is provided.
  3. No overview of what exceptions (if any) are thrown is provided.
  4. The provided code sample is seemingly incomplete. (Where are x and y declared? There is also apparently a call to function move_CharacterBody2D in the event handler, but the provided sample does not include a definition for this function.)

Please don’t take this the wrong way, but are you by any chance a beginner at programming in GDScript? You might be better served by reading the documentation and trying a few sample projects first.

2 Likes

Not enough information to help you much, but I see couple things wrong here:
y 300
Maybe should be:
y, 300

And you are doing something strange here:
var CharacterBody2D
Using a class name as the name for a var. I assume it’s also the name of a node in your scene.

what I am trying to do is that if the player hits the collision(underworld)
the player will respawn at 0,0

I will thanks

extends Area2D

var CharacterBody2D
var entered = true

func _on_CharacterBody2D_eneter_underworld():
if entered: move_CharacterBody2D(x, 100, y 300)