LuaUnitGroup's set_command not being done by group entitie

Place to get help with not working mods / modding interface.
Post Reply
User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

LuaUnitGroup's set_command not being done by group entitie

Post 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
Last edited by StanFear on Tue Mar 22, 2016 6:50 pm, edited 1 time in total.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Any way to know when a (unit) command is over ?

Post by prg »

Make the entity part of a unit group, order the group around, check for group.state == defines.groupstate.finished.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: Any way to know when a (unit) command is over ?

Post 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 !

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: Any way to know when a (unit) command is over ?

Post 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 ?

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Any way to know when a (unit) command is over ?

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: Any way to know when a (unit) command is over ?

Post 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 !)

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Any way to know when a (unit) command is over ?

Post 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?
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: Any way to know when a (unit) command is over ?

Post 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

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: LuaUnitGroup's set_command not being done by group entitie

Post by StanFear »

So that people can test and understand the issue :
the mod in its current state :
Subsurface_0.0.3.zip
the mod
(1.6 MiB) Downloaded 52 times
to reproduce the issue :
  1. Create a new game
  2. craft a surface driller
  3. place the surface driller and power it
  4. wait for the drill to finish its job
  5. go to the underground (by standing near the center of the newly placed entity
  6. once underground, make room for a "digging-robots-deployment-center" (3x3) and place it
  7. create an assembled digging robot and place it in the deployment center
  8. 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
  9. 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 54 times

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: LuaUnitGroup's set_command not being done by group entitie

Post 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 !

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: LuaUnitGroup's set_command not being done by group entitie

Post by Adil »

Beware, the AI_controllable might as well enable hardcoded behavior (the one biters use) on soldiers.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

Post Reply

Return to “Modding help”