Using two say commands for two different types


#1

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?


#2

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:


#3

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.


#4

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.)


#5

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}} ] );