venus-e
February 24, 2025, 4:23am
21
It does run, but the variable it needs to continue down the chain never changes to true.
All the relevant code:
class_name squareBlock
extends Sprite2D
@onready var square_block: squareBlock = get_node("/root/Node2D/Blocks/squareBlock")
@onready var square_block_hitbox: Area2D = $squareBlock
@onready var in_play_piece: Sprite2D = get_node("/root/Node2D/inPlayPiece")
@onready var next_piece: Sprite2D = get_node("/root/Node2D/nextPiece")
var main = mainGame.new()
var pieceName = "squareBlock"
func _process(delta: float):
if varStor.sq_ready == true:
print("block ready")
if varStor.activePieces.front() == pieceName:
attachBlock(square_block, in_play_piece)
elif varStor.activePieces.back() == pieceName:
attachBlock(square_block, next_piece)
func attachBlock(whatToAttach, attachTo):
whatToAttach.position = Vector2(attachTo.position.x, attachTo.position.y)
and the global variables:
extends Node2D
var sq_ready := false
var activePieces: Array[String] = ["squareBlock", "lBlock"]
func _on_start_timer_timeout():
sq_ready = true
What does this print when placed in the global script? Does it print more than once?
func _ready() -> void:
print(get_path())
venus-e
February 24, 2025, 4:26am
23
It prints this block:
/root/varStor
/root/Node2D/Blocks/squareBlock/variableStorage
/root/Node2D/Blocks/variableStorage
/root/Node2D/variableStorage
/root/Node2D/squareBlock/variableStorage
That’s a lot of variable storages! The only one that is really a global is /root/varStor, and it’s created automatically by the Global/Autoload/Singleton system. However, you added the script .gd as a Global which does not create any of the children (the timer) or connections to signals (it’s timeout) that you expect, instead you can add the scene .tscn as a Global and it will.
venus-e
February 24, 2025, 4:33am
25
So add the global script as a scene or add the scenes as globals?
You should have one scene with the specified script on the root node. Add that scene as a global varStor, delete all other variableStorage nodes.
venus-e
February 24, 2025, 4:35am
27
Add the scene varStor.tscn as a global?