Also I have main scene, where I have player and duplicated “Player2”
For some reason, when I select “Player” by pressing “Lclick”, Global.selected variable changes to “true”, but when I select “Player2”, Global.selected variable still return “false”, although variables in player script works fine. Why is that?
My best guess is that both player-objects are reacting to the Lclick input, with setting Global.selected to false, and another setting it to true. So which result you get depends on the order of execution - one overwrites the other.
I mean, it’s mostly the deselecting that’s the problem, right? The code in your else branch should only run if this was actually the object that was selected. Something like:
func _input(event):
if event.is_action_pressed("Lclick"):
if selectable == true:
Global.selected = true
selected = true
get_node("Circle").modulate = Color(1, 1, 1)
elif selected: # this object is selected, but we clicked outside of it
Global.selected = false
selected = false
$Circle.visible = false
Might do the trick?
Edit: Although that still won’t quite work if we have object A selected, and then click on object B to change the selection…
Well, my brain desided to actually work for once and I figure out that I could create an array in my Mark creating system, so when I select a troop it appends into this array and if array size != 0, mark is creating and it worked