Using two say commands for two different types

I am trying to give my Soldiers and Archers a different command through say.

self.say(“Defend!”, { “type”: “archer”, “targetPos”: {“x”: self.pos.x - 5, “y”: self.pos.y + 5}})
self.say(“Defend!”, { “type”: “soldier”, “targetPos”: {“x”: self.pos.x - 5, “y”: self.pos.y - 5}})

However, only the last say seems to work.

How can I achieve this?

I don’t think its a spelling error, unless archer is supposed to be archers or something weird. This is going to require a better programmer than me :frowning:

Well if I flip the statements (soldier above archer) then only the archers listen. So individually they work, but only the last of the two is being used.

You can only say one thing per frame, so the last one is overwriting the first. You could try alternating which command you’re saying once per second based on this.now(). (But it’s things like this that made us abandon the say API for commanding troops in favor of the command API used in Greed and Sky Span.)

Nothing prevents you from combining the two objects, I think…

Something like this :
self.say(“Defend!”, { “archer”: { “targetPos”: {“x”: self.pos.x - 5, “y”: self.pos.y + 5} },
“soldier”: { “targetPos”: {“x”: self.pos.x - 5, “y”: self.pos.y - 5} } } );

Or like this :
self.say(“Defend!”, [ { “type”: “archer”, “targetPos”: {“x”: self.pos.x - 5, “y”: self.pos.y + 5}},
{ “type”: “soldier”, “targetPos”: {“x”: self.pos.x - 5, “y”: self.pos.y - 5}} ] );