Page 1 of 1

Question: Compound Commands to units

Posted: Wed Jan 18, 2017 9:01 pm
by Humpfry
Can someone give an example on how to utilize defines.command.compound


defines.command.compound
structure_type :: defines.compound_command: How the commands should be chained together.
commands :: array of Command: The sub-commands.


Not too sure what is the structure_type is:

{ defines.command.compound, defines.compound_command.logical_and, ... , ...}
or
{defines.command.compound, defines.compound_command.logical_and, { {...} , {...} } }

ie move to multiple rally points then build a base without being distracted as an example

set_multi_command{command=…, unit_count=…, force=…, unit_search_distance=…} → uint

Code: Select all

surface.set_multi_command{ {defines.command.compound, 
                defines.compound_command.return_last ,
                {defines.command.go_to_location, {x = 50, y = 20}, defines.distraction.none} ,
                {defines.command.go_to_location, {x = 60, y = 20}, defines.distraction.none} ,
                {defines.command.go_to_location, {x = 70, y = 20}, defines.distraction.none} ,
                {defines.command.go_to_location, {x = 80, y = 20}, defines.distraction.none} ,
                {defines.command.build_base, {x = 80, y = 20}, defines.distraction.none} },
                          10,
                           "enemy",
                           32}
or

Code: Select all

surface.set_multi_command{ defines.command.compound, 
                defines.compound_command.return_last , 
                { {defines.command.go_to_location, {x = 50, y = 20}, defines.distraction.none} ,
                  {defines.command.go_to_location, {x = 60, y = 20}, defines.distraction.none} ,
                  {defines.command.go_to_location, {x = 70, y = 20}, defines.distraction.none} ,
                  {defines.command.go_to_location, {x = 80, y = 20}, defines.distraction.none} ,
                  {defines.command.build_base, {x = 80, y = 20}, defines.distraction.none} },
                          10,
                           "enemy",
                           32}
I might have made it worse off to use the surface.set_multi_command as an example. Maybe use entity.set_command(cmd) instead. I am more interested in the cmd than the method.

Or something else, just not too sure on structure. Notice the extra brackets on the 2nd example.

Re: Question: Compound Commands to units

Posted: Wed Jan 18, 2017 9:54 pm
by Klonan
Something like this:

Code: Select all

unit.set_command
{
  type = compound,
  structure_type = structure, 
  commands = 
  {
    {type = go_to, destination = destination},
    {type = attack, target = target, distraction = distraction}
  }
}