- Edited
So, this may be complicated, my code is probably not the most streamlined, but the basic point is I have a left click select func, and a right click attack func, these use for loops. The select func that I have made seems to do what I want it to, however the attack func will only do what I want it to for the first ship in my array. If I do the same thing with the second ship it returns my else statement in the attack func. Why would this sorting possibly be causing an issue like that? Here is the code I believe would be relevant.
func selector(source):
selectorActive = true
var selected = get_tree().get_nodes_in_group("selected")
var origin = get_node(get_path_to(source.find_child("Selection")))
var ship = get_node(get_path_to(source))
for selector in selected:
selector.visible = false
if ship.select == false:
for ships in arrShip:
ships.select = false
origin.visible = true
ship.select = true
else:
for ships in arrShip:
ships.select = false
origin.visible = false
selectorActive = false
func move_turn():
var sortNum = 0
#Sorts the ships based on initiative in order to call turn order
if sortNum == turnMove:
arrShip.sort_custom(func(a, b): return a.initiative<b.initiative)
sortNum += 1
if theUnit.turnCount == turnMove:
ship_cycle()
else:
end_move_turn()
show_buttons(theUnit.active)
func attack_action(attacked, attacker):
var origin
var target = get_node(get_path_to(attacked))
for ship in arrShip:
if ship.select == true:
origin = ship
attacker = get_node(get_path_to(origin))
print(attacker,' ', attacked,)
else:
print('why does my second ship choose the else statement rather than the first')
return