Godot Version
4.5
Question
I am making a cookie clicker type game and i have some shop buttons in a “shop” scene inside of a “gui” scene inside of a “main” scene. Inside of the shop scene i have buttons that i want to send a signal i can connect to the main scene but i am having trouble doing that. Im basicly asking how to connect a signal through 2 or more scenes. If it helps here is my code:
Shop script:
extends Control
signal click_boost_upgrade_pressed(node, cost)
signal idle_clicker_upgrade_pressed(node, cost)
@onready var idle_btn = get_node("HBoxContainer/idle_clicker_upgrade_button")
@onready var boost_btn = get_node("HBoxContainer/click_boost_upgrade_button")
var idle_cost = 20
var boost_cost = 40
func _ready():
await get_tree().process_frame
idle_btn.pressed.connect(_on_idle_pressed)
boost_btn.pressed.connect(_on_boost_pressed)
func _on_idle_pressed():
emit_signal("idle_clicker_upgrade_pressed", self, idle_cost)
func _on_boost_pressed():
emit_signal("click_boost_upgrade_pressed", self, boost_cost)
GUI script:
extends Control
signal click_boost_upgrade_pressed(node, cost)
signal idle_clicker_upgrade_pressed(node, cost)
@onready var shop = get_node("Shop")
func _ready():
await get_tree().process_frame
shop.click_boost_upgrade_pressed.connect(func(node, cost): emit_signal("click_boost_upgrade_pressed", node, cost))
shop.idle_clicker_upgrade_pressed.connect(func(node, cost): emit_signal("idle_clicker_upgrade_pressed", node, cost))
Main script:
extends Control
@onready var coin = get_node("Coin")
@onready var coin_text = get_node("GUI/coin_text")
var coins = 0
var coin_boost = 0;
var coin_boost_multi = 0;
var coin_idle = 0;
var coin_idle_multi = 0;
func _on_coin_coin_clicked():
coin_add(1 + coin_boost)
var x = randf_range(5, 950)
var y = randf_range(-20, 440)
while x > 585 or x < 370 and y < 125:
x = randf_range(5, 950)
y = randf_range(-20, 440)
coin.position = Vector2(x, y)
func _on_idle_timer_timeout():
coin_add(coin_idle)
func coin_add(amount):
coins += amount
coin_text.text = "Coins: " + str(coins)
func _on_gui_click_boost_upgrade_pressed(boost_btn, cost):
coin_boost += 1 * coin_boost_multi
boost_btn.boost_cost = cost + cost / 2 + cost / 5
func _on_gui_idle_clicker_upgrade_pressed(idle_btn, cost):
coin_idle += 1 * coin_idle_multi
idle_btn.idle_cost = cost + cost / 2 + cost / 5
I believe the problem is somewhere in the GUI or Shop script but i just cant fix it.