Page 1 of 1
LuaUnitGroup's set_command not being done by group entitie
Posted: Mon Mar 21, 2016 11:19 pm
by StanFear
Hi,
Just need to know if there is a way to know when a command set to an entity using set_command() is accomplished
has_command does not seem to be able to handle that (it always return true for me ...)
Update : thanks to prg I know that I can track the progress of an entity by adding it to a Unit group, now, the problem is :
When I assign an entity to a group and have the groupe attack a wall, the entity just stays there, and the group state quickly change to finished whithout having anything happen
Re: Any way to know when a (unit) command is over ?
Posted: Mon Mar 21, 2016 11:40 pm
by prg
Make the entity part of a unit group, order the group around, check for group.state == defines.groupstate.finished.
Re: Any way to know when a (unit) command is over ?
Posted: Tue Mar 22, 2016 8:58 am
by StanFear
prg wrote:Make the entity part of a unit group, order the group around, check for group.state == defines.groupstate.finished.
this seems promissing, and it might make checking if the command is over not necessary, I'll just be able to use groupstate.attacking_target, which is what I originnaly wanted, so ...
Thank you !
Re: Any way to know when a (unit) command is over ?
Posted: Tue Mar 22, 2016 11:24 am
by StanFear
ok, I come with updates,
I think giving commandes to units doesn't work
I have this piece of code :
Code: Select all
data.deployed_unit_group = data.deployment_center.surface.create_unit_group{position = deployment_position, force = data.deployment_center.force}
local entity = data.deployment_center.surface.create_entity{name=entity_name, position=deployment_position, force=data.deployment_center.force}
data.deployed_unit_group.add_member(entity)
data.deployed_unit_group.set_command({type=defines.command.attack, target=target_wall, distraction=defines.distraction.none})
data.deployed_unit_group.start_moving()
entity.set_command({type=defines.command.group, group = data.deployed_unit_group, distraction=defines.distraction.none})
and what it does is .... absolutely nothing ... the entity stays blocked for some time, then start wandering about ...
I printed on each tick the state of the group : it directly goes to finished (gathering -> finished)
any idea ?
Re: Any way to know when a (unit) command is over ?
Posted: Tue Mar 22, 2016 11:40 am
by prg
Hm, something similar is working for me. The position the group is created in needs to be reachable by the members, but I guess it is since you're able to create an entity in the same position that wanders around. I don't even need the last set_command call for the entity, just adding it is enough to make it follow the group. So... can't tell by just looking at that piece of code.
Re: Any way to know when a (unit) command is over ?
Posted: Tue Mar 22, 2016 1:28 pm
by StanFear
prg wrote:So... can't tell by just looking at that piece of code.
ok, well, the code is right there :
https://github.com/stanfear/FactorioMod ... ol.lua#L93
the function is at line 93 (you should arrive there with the link)
the code from before is extracted from lines 100 and next
I really hope you'll see something I did not !
(and if you need help understanding my code, just ask !)
Re: Any way to know when a (unit) command is over ?
Posted: Tue Mar 22, 2016 2:02 pm
by prg
Is the wall you're trying to attack a valid entity? Does the unit move if you tell it to go_to_location with a hardcoded, reachable destination?
Re: Any way to know when a (unit) command is over ?
Posted: Tue Mar 22, 2016 3:22 pm
by StanFear
prg wrote:Is the wall you're trying to attack a valid entity? Does the unit move if you tell it to go_to_location with a hardcoded, reachable destination?
well, when I give the same command to the entity directly, it works (the unit start atacking the wall)
it's only when using a unit group that it doesn't work
Re: LuaUnitGroup's set_command not being done by group entitie
Posted: Thu Mar 24, 2016 1:59 pm
by StanFear
So that people can test and understand the issue :
the mod in its current state :
to reproduce the issue :
- Create a new game
- craft a surface driller
- place the surface driller and power it
- wait for the drill to finish its job
- go to the underground (by standing near the center of the newly placed entity
- once underground, make room for a "digging-robots-deployment-center" (3x3) and place it
- create an assembled digging robot and place it in the deployment center
- mark an area with the "selection-marker" from the toolbelt (deconstruction planner icon) -> click at one place, then clock at another with the item still in hand
- a medium bitter should apear and ... not move (sadly)
or : download this save, load it and power the deployment center
- Setup.zip
- the save that allows to not have to do all the boring stuff to test the bug
- (579.66 KiB) Downloaded 69 times
Re: LuaUnitGroup's set_command not being done by group entitie
Posted: Mon May 02, 2016 1:00 pm
by StanFear
I might have figured out why this wasn' t working!
from the documentation in LuaForce :
ai_controllable :: boolean [Read-Write]
Enables some higher-level AI behaviour for this force. When set to true, biters belonging to this force will automatically expand into new territories, build new spawners, and form unit groups. By default, this value is true for the enemy force and false for all others.
Note: Setting this to false does not turn off biters' AI. They will still move around and attack players who come close.
Note: It is necessary for a force to be AI controllable in order to be able to create unit groups or build bases from scripts.
and I'm pretty sure the force I was working with was not ia_controllable.
I am not 100% certain that this is the reason, but putting it out there won't hurt anyone !
Maybe the waring should be written in the lua doc in the function description !
Re: LuaUnitGroup's set_command not being done by group entitie
Posted: Mon May 02, 2016 1:35 pm
by Adil
Beware, the AI_controllable might as well enable hardcoded behavior (the one biters use) on soldiers.