Page 1 of 1
Shooting state is not writeable
Posted: Fri Jul 28, 2017 8:19 pm
by Valansch
The API states:
shooting_state [Read-Write]
http://lua-api.factorio.com/latest/LuaC ... ting_state
yet
Code: Select all
game.players[1].shooting_state.state = defines.shooting.shooting_enemies
game.print(game.players[1].shooting_state.state)
Will always return the shooting state before running the code. Even if enemies are in range.
I don't know if this is a bug, or i'm misunderstanding something or if the API documentation is wrong.
Re: Shooting state is not writeable
Posted: Sat Jul 29, 2017 8:59 am
by Choumiko
It is writeable. You just have to assign the whole state, not just a field of it
Code: Select all
game.players[1].shooting_state = {state = defines.shooting.shooting_enemies, position = game.players[1].shooting_state.position}
game.print(game.players[1].shooting_state.state)
For most (if not all) tables you get back from the api, writing works only if you reassign the complete table.
Re: Shooting state is not writeable
Posted: Sat Jul 29, 2017 9:52 am
by Valansch
I thought someone might say that. Sry I didn't clarify, but this was the first thing I tried. I does not work.
Re: Shooting state is not writeable
Posted: Sat Jul 29, 2017 11:42 pm
by Choumiko
You might have to do it every tick, that's how i do it here:
https://github.com/Choumiko/UnminableVe ... l.lua#L156
I assume since the shooting state is controlled via player input normaly it gets reset every tick if the configured key isn't pressed
Re: Shooting state is not writeable
Posted: Sun Jul 30, 2017 12:05 am
by Valansch
The code you are linking works. You can stop a player from attacking something.
But i didn't have any luck setting the shooting state to anything else than 0.
So the shooting state is writable. But only 0 is a legal value?
Re: Shooting state is not writeable
Posted: Tue Oct 24, 2017 1:35 pm
by Relik
Hi,
I have the same problem : I'm trying to create a mod that allows to automate vehicles (car, tank) and I can't get them to attack :/
Did you find a solution ?
I tried :
Code: Select all
car.passenger = car.surface.create_entity({
name = "player",
force = player.force,
position = car.position
})
car.passenger.shooting_state = {
state = defines.shooting.shooting_selected,
position = { x = car.position.x + 1, y = car.position.y }
}