Beginner having issues with syntax

Godot Version

extends Node2D

@onready var color_rect = $platforms/platform/ColorRect
var is_colliding = false

func _on_platform_area_entered(area: Area2D) β†’ void:
is_colliding = true

print("Colliding")

func change_color():
if is_colliding:
color_rect.color = Color(1, 0, 0)

Question

Hello good people of the forum! im a beginner in coding and Im trying to escape tutorial hell and make some simple games on my own. Yet as you will see im struggling with pretty simple tasks such as writing correct syntax.
Here im trying to make the color.rect change color when the player collides with the Area2d node. I am using groups for my Area2d nodes and the _on_area_entered function works correctly as the debugger prints when the player collides with the platform, however I cant seem to figure out how to set up the color change correctly. Any help would be greatly appreciated!
Cheers

func change_color()

You need to call this function from somewhere. Maybe after the print("Colliding")

There is a toolbar on the window where you type your posts here. On that toolbar is an item that looks like this </>. That button encloses your posted code in such a way as to preserve tabs.
Code that is posted without that is all but unreadable as you can see in your post.

2 Likes

sancho2
You need to call this function from somewhere. Maybe after the print(β€œColliding”)

You can use it:

extends Node2D

@onready var color_rect = $platforms/platform/ColorRect
var is_colliding = false

func _on_platform_area_entered(area: Area2D) β†’ void:
  is_colliding = true
  print("Colliding")

func _process(delta):
  if is_colliding:
    color_rect.color = Color(1, 0, 0)

or it for less processing:

extends Node2D

@onready var color_rect = $platforms/platform/ColorRect
var is_colliding = false

func _on_platform_area_entered(area: Area2D) β†’ void:
  is_colliding = true
  print("Colliding")
  change_color()

func change_color():
  color_rect.color = Color(1, 0, 0)
1 Like

Hey, thanks for the reply I figured out the issue, i was using multiple colorRect inside a Node which apparently messes with their anchors being bundled at 0,0 and therefore my player was insta colliding with it. My bad, you live and you learn I guess