How to make the 1st script work like the 2nd. It’s hard to explain, but the first script sends a signal with the same last position for all units, rather than in order for each. How to make the signal sent in the order of the array of units #1
var targetPositionList = [Vector2(50, 50),Vector2(60, 60)]
var targetPositionListIndex = 0
for unit in units:
if unit.selected:
SignalManager.give_pos.emit(targetPositionList[targetPositionListIndex])
targetPositionListIndex = (targetPositionListIndex + 1) % targetPositionList.size()
print(targetPositionListIndex)
#2
var targetPositionList = [Vector2(50, 50),Vector2(60, 60)]
var targetPositionListIndex = 0
for unit in units:
if unit.selected:
unit.position = targetPositionList[targetPositionListIndex]
targetPositionListIndex = (targetPositionListIndex + 1) % targetPositionList.size()```
Is there any reason you would use the first sample, it seems like you want to use a for loop with the units directly like in #2. You cannot achieve #2 with a signal, since emitting is by definition going to all connected functions, not just one unit at a time.
bro, I solved the problem, in the unit script I then simply check the id.
var targetPositionList = get_position_list_around(local_position, 8, 4)
var targetPositionListIndex = 0
for unit in units:
if unit.selected:
var unit_id = unit.get_instance_id()
SignalManager.give_pos.emit(targetPositionList[targetPositionListIndex], unit_id)
targetPositionListIndex = (targetPositionListIndex + 1) % targetPositionList.size()