Need help with checkpoint script!

Godot Version

4.2.1

Question

Hi there, I need help with a checkpoint script for a test platformer I’ve been making with godot
i have dyscalculia, which is one of the reasons why it’s really hard for me to easily learn code, though I’m trying my best. I am more of an artist, not really a programmer though.

I got the script from a youtuber, but the problem is idk how to make it so that you can switch back to older checkpoints and undo the color changes of previous checkpoints. Also I can’t figure out how to make the color of the checkpoint actually change.

here is the script, how would I edit the script to undo changes to last checkpoint and update the changes for each time a checkpoint is touched?

extends StaticBody2D
class_name checkpoint

@export var spawnpoint = false

var activated = false

func activate():
		global.current_checkpoint = self
		activated = true
		Color("Dark_Red")


func _on_area_entered(area):
	if area.get_parent() is player_character:
		activate()

If you can make your project source available somewhere, I would be happy to look at it and see if I can help you.

so I updated my checkpoint script a bit, fixing most of the issues, but I was wondering how do you make the last checkpoint revert back to it’s default self_modulate value after hitting another checkpoint?

here is my script for my checkpoint

extends StaticBody2D
class_name checkpoint

@export var spawnpoint = false

var activated = false

func _ready():
	if spawnpoint:
		activate()

func activate():
	global.current_checkpoint = self
	activated = true
	$Sprite2D.self_modulate = Color("DARK_RED")

func _on_area_entered(area):
	if area.get_parent() is player_character:
		activate()

You are saving checkpoint node to global.current_checkpoint, so you can access it children with get_node function.

extends StaticBody2D
class_name checkpoint

@export var spawnpoint = false

var activated = false

func _ready():
	if spawnpoint:
		activate()

func activate():
	if global.current_checkpoint:
		global.current_checkpoint.get_node("Sprite2D").self_modulate = Color.WHITE
	global.current_checkpoint = self
	activated = true
	$Sprite2D.self_modulate = Color("DARK_RED")

func _on_area_entered(area):
	if area.get_parent() is player_character:
		activate()

Thank you for helping!

Glad you got help. At least you know more now than a few days ago! Good luck.

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