I want Code of Button to do things connected to it on Current scene without bugging other scenes

godot 4.4

For Example i want Button in level 1 to Open Doors and show and hide platform, but in level 2 i want same button with same code to turn off BuzzSaw without changing Main Button’s Code just changing one in Scene
here is my Code

extends Area2D

var is_open = false

# Called when the node enters the scene tree for the first time.
func _ready():
	pass



# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass
func on_interact(player: Node) -> void:
	print("Ouch! I've been interacted")
	is_open = !is_open #Toggle is_open to be the opposite of whatever it was before
	if is_open:
		pass
		
	else:
		pass



Door Code 

extends StaticBody2D

@onready var door: CollisionShape2D = %DoorCollison



func Is_Open():
	door.disabled = true
	%AnimatedSprite2D.play("Open")
func Is_closed():
	door.disabled = false
	%AnimatedSprite2D.play("Close")

Sounds a bit messy. Why not just use 2 buttons?

Otherwise, you could just store which stage you are at in some script. Either in root, some global or whatever you prefer.

something like:
var current_stage = 2

Then in the button-script, access the place where you store which stage you are at. If it is a global named StageManager your would do that by writing:

current_stage = StateManager.current_stage

Then in your button code you perform a check before you execute the code:

current_stage = StateManager.current_stage (set it at the start of the function, so it's always updated before the rest of the code runs)
if current_stage == 1:
do stage 1 stuff
if current_stage == 2:
do stage 2 stuff

It makes no sense to me though. It would probably be less work, less buggy, easier to maintain etc to just use 2 separate buttons.

Wouldn’t it be easier to code the individual objects, and have them listen for the _on_button_pressed() signal to do the thing? You could even code custom signals if you really wanted all the code to be on the button, and just have it send out the approproate signal based on what the current scene is.

my Button Node is Area 2d so it doesnt have signals, plus how to make signals? like when i press button i want it to call Func on Door node (func Is_open() ) to play whats inside