I’m sorry for not being clear enough. I’ve changed the ‘move forward’ signal back to the built in signals, as i’d love to use them if possible. They are lot more straight forward. I left the ‘hover’ signals as custom ones to compare for now.
Currently, BOTH ways are working as intended on the buttons that are in the scene tree to start, but do not work on instantiated buttons. This is the issue.
I’ve attached all the relevant code, in a much prettier way, thank you dragonforge-dev!
The racehorse code:
class_name racehorse
extends CharacterBody2D
var speed = 100
#moves
var nomove := Vector2(0.0,0.0)
var straight := Vector2(0.0, -speed)
var hardleft := Vector2( -0.5*speed, -0.5*speed)
var hardright := Vector2(+0.5*speed, -0.5*speed)
var bigstraight := Vector2(0.0, -1.5*speed)
var smallleft := Vector2(- 0.25*speed, -speed)
var smallright := Vector2(+.25*speed, -speed)
var target = position
func _ready() -> void:
target = nomove
$targetlocation.visible=false
# Called every frame. 'delta' is the elapsed time since the previous frame.
@warning_ignore("unused_parameter")
func _process(delta: float) -> void:
pass
@warning_ignore("unused_parameter")
func _physics_process(delta):
velocity = position.direction_to(target) * speed
$racehorsesprite.pause()
if position.distance_to(target) > 10:
move_and_slide()
$racehorsesprite.play()
$targetlocation.visible=false
func _on_button_2_pressed() -> void:
target += hardleft
#func playcard():
#var emitting_node = get_node("../straightbutton")
#emitting_node.straightpressed.connect(_on_straightbutton_straightpressed) # Connect the signal
#func _on_straightbutton_straightpressed() -> void:
#print("straight")
#target += straight
func hover():
var emitting_node = get_node("../straightbutton")
emitting_node.straighthover.connect(_on_straightbutton_straighthover)
emitting_node.straightexit.connect(_on_straightbutton_straightexit)
func _on_straightbutton_straighthover() -> void:
$targetlocation.position = straight
$targetlocation.play()
$targetlocation.visible=true
func _on_straightbutton_straightexit() -> void:
$targetlocation.visible=false
func _on_button_2_mouse_entered() -> void:
$targetlocation.position = hardleft
$targetlocation.visible=true
func _on_button_2_mouse_exited() -> void:
$targetlocation.visible=false
func _on_straightbutton_mouse_entered() -> void:
$targetlocation.position = straight
$targetlocation.play()
$targetlocation.visible=true
pass # Replace with function body.
func _on_straightbutton_pressed() -> void:
print("straightx")
target += straight
here is the code for the straight button:
class_name straightbutton
extends Button
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass
# pressed.connect(_on_straightpressed)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
#signal straightpressed()
#func _on_straightpressed() -> void:
# straightpressed.emit()
# print("pressed")
# queue_free()
signal straighthover()
signal straightexit()
func _on_mouse_entered() -> void:
straighthover.emit()
func _on_mouse_exited() -> void:
straightexit.emit()
here is the code for instantiating the buttons:
extends Node2D
# Called when the node enters the scene tree for the first time.
var straightbutton = preload("res://straightbutton.tscn")
var leftbutton = preload("res://leftbutton.tscn")
var rightbutton = preload("res://rightbutton.tscn")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
var deck = [$straightbutton, $straightbutton, $straightbutton, $straightbutton, $straightbutton, $leftbutton, $leftbutton, $leftbutton, $rightbutton, $rightbutton, $rightbutton]
var hand = []
var discardpile = []
func _ready() -> void:
deck.shuffle()
if hand.size() < 5:
hand.append(deck[-1])
deck.pop_back()
else:
print(hand.size)
hand_show()
func hand_show():
var straightbuttonload = straightbutton.instantiate()
var leftbuttonload = leftbutton.instantiate()
var rightbuttonload = rightbutton.instantiate()
for straightbutton in hand:
$CanvasLayer/Control/MarginContainer/VBoxContainer/HBoxContainer.add_child(straightbuttonload)
for leftbutton in hand:
$CanvasLayer/Control/MarginContainer/VBoxContainer/HBoxContainer.add_child(leftbuttonload)
for rightbutton in hand:
$CanvasLayer/Control/MarginContainer/VBoxContainer/HBoxContainer.add_child(rightbuttonload)
func drawcard():
if deck.is_empty():
deck.shuffle()
if hand.size() < 5:
hand.append(deck[-1])
deck.pop_back()
hand_show()
lastly a screenshot of the nodetree:
I was trying out a signalbus to see if that would work but i don’t think its needed.
Thank you all for your suggestions and help so far !!!