[Solved] Can't write to vehicle_automatic_targeting_parameters

Place to get help with not working mods / modding interface.
Post Reply
User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 768
Joined: Sun May 07, 2017 10:16 am
Contact:

[Solved] Can't write to vehicle_automatic_targeting_parameters

Post by ickputzdirwech »

I want to write to the vehicle_automatic_targeting_parameters but it just won't work. Here the full code:

Code: Select all

script.on_event(defines.events.on_lua_shortcut, function(event)
  local prototype_name = event.prototype_name
  local player = game.players[event.player_index]
  if prototype_name == "targeting-with-gunner" then
    if player.driving == true then
      if player.vehicle.type == "spider-vehicle" then
        if player.vehicle.vehicle_automatic_targeting_parameters.auto_target_with_gunner == true then
          player.vehicle.vehicle_automatic_targeting_parameters.auto_target_with_gunner = false
          player.set_shortcut_toggled(prototype_name, false)
        else
          player.vehicle.vehicle_automatic_targeting_parameters.auto_target_with_gunner = true
          player.set_shortcut_toggled(prototype_name, true)
        end
      end
    end
  end
end)
Everything works just fine except the two lines were I try to change vehicle_automatic_targeting_parameters.auto_target_with_gunner to true/false. I am using the same code for enable_logistics_while_moving and it works:

Code: Select all

player.vehicle.enable_logistics_while_moving = false
What am I doing wrong?
Last edited by ickputzdirwech on Sun Oct 04, 2020 10:30 am, edited 1 time in total.
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Can't write to vehicle_automatic_targeting_parameters

Post by Choumiko »

You have to write the entire table:

Code: Select all

local params = player.vehicle.vehicle_automatic_targeting_parameters
params.auto_target_with_gunner = true
player.vehicle.vehicle_automatic_targeting_parameters = params
Whenever something is RW and it returns a table you have to write the whole table, even if you just want to change one key.

User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 768
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: Can't write to vehicle_automatic_targeting_parameters

Post by ickputzdirwech »

Thank you for you help! It works perfectly. I learned something new again. But to be honest I don't entirely understand why it works this way. The first two lines are pretty much the same I had before. And the third line somehow assembles everything together again?
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write

Post Reply

Return to “Modding help”