Page 1 of 1

Unit command - target vs destination

Posted: Wed Nov 13, 2013 10:35 pm
by FreeER
The attack command requires a "target" variable/key, but every other command requires "destination". I'd suggest changing one, though I'm not sure which, attack would be obvious since there would be less to change, but I believe it is the only command used in any control.lua (both base and mod, unless the old CC mod used more) besides wander (which won't change)

Re: Unit command - target vs destination

Posted: Thu Nov 14, 2013 12:38 pm
by SilverWarior
FreeER wrote:I'd suggest changing one, though I'm not sure which, attack would be obvious since there would be less to change
I don't think they will ever change attack command. Why? If you change attack command to accept location instead of target you lose the ability to attack moving targets since their location is constantly changing.

I asume you would like to be able to to send units to certain location and attack whatever it is out there.
If my asumption is correct then I suggest you check how crepers "distraction" was set up since their primary target was always player character. I think that might be able to work with combination of move to location command.

Re: Unit command - target vs destination

Posted: Thu Nov 14, 2013 3:37 pm
by FreeER
Actually, what I meant was not to change how the command actually functions but how you call it. The attack command is {type=defines.command.attack, target=entity, distraction=defines.distraction.whatever} where every other command is {type, destination, distraction}. I made a wiki page from what I saw in the code (and what I tested ingame) here. You might notice that gotolocation will accept either a location or an entity even though it uses destination (which makes sense).

Re: Unit command - target vs destination

Posted: Fri Nov 15, 2013 10:56 am
by SilverWarior
FreeER wrote:You might notice that gotolocation will accept either a location or an entity even though it uses destination (which makes sense).
But does it update this location when entity moves? If the answer is yes then your suggestion could be valid.

Re: Unit command - target vs destination

Posted: Fri Nov 15, 2013 11:08 am
by FreeER
SilverWarior wrote: But does it update this location when entity moves? If the answer is yes then your suggestion could be valid.
hm, good question. I'm not sure since I used a nearby tree :) I kind of doubt it but I'll find out and edit

edit:hm...apparently I did not personally check the gotolocation command with an entity, there is c++ code for goto to work with an entity* but the lua interface only tries to get a RealPosition, thus passing an entity fails (with a "LuaEntity doesn't contain readable property x")

Re: Unit command - target vs destination

Posted: Fri Nov 15, 2013 3:35 pm
by kovarex
Both move to and attack should accept both entity or position.
Similar to starcraft, where you have either attack or attack move. (Or follow/move)

Re: Unit command - target vs destination

Posted: Fri Nov 15, 2013 6:19 pm
by FreeER
kovarex wrote:Both move to and attack should accept both entity or position.
Similar to starcraft, where you have either attack or attack move. (Or follow/move)
should as in: they already do or should as in: this is what we wanted to happen but is not currently happening and will be fixed soon?
because I've already mentioned passing an entity to gotolocation fails (property x) and passing a position (like {61.2, -300.9}) to attack fails due to "Given object is not lua entity".

However given there are two lua commands for attack, why should attack also work with position? It makes more sense (to me) to have it only use entity and have attackarea use position and radius (as is the case now).

Admittedly I've done this testing through the console but I don't think that matters here :) (not to mention, if I'm reading it right, the LuaHelper parseCommand and it's switch will back me up lol)

however, to remention the original topic, the attack command wants a table with target (ex: {target=game.player.selected}) and the other commands want a table with destination ({destination={x,y}} or {destination=game.player.selected.position}), admittedly if attack is the only command that accepts an entity this makes some sense.