Spider-vehicle: How do I set "Request from buffer chests?"

Place to get help with not working mods / modding interface.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1758
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Spider-vehicle: How do I set "Request from buffer chests?"

Post by Pi-C »

Using vehicle.vehicle_logistic_requests_enabled allows me to change the state of a spider-vehicles "Personal logistics and auto-trash" checkbox, but I can't figure out how to modify the "Request from buffer chests" checkbox. Apparently, vehicle.request_from_buffers works for requester chests only, not for spider-vehicles. Could somebody tell me which property I need to modify that checkbox?
buffer-request.png
buffer-request.png (61.09 KiB) Viewed 1378 times
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Spider-vehicle: How do I set "Request from buffer chests?"

Post by mrvn »

From https://lua-api.factorio.com/latest/Classes.html:

vehicle_logistic_requests_enabled
:: boolean
[RW]

If personal logistic requests are enabled for this vehicle (spidertron).
Pi-C
Smart Inserter
Smart Inserter
Posts: 1758
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Spider-vehicle: How do I set "Request from buffer chests?"

Post by Pi-C »

mrvn wrote: Mon Sep 12, 2022 9:09 pm From https://lua-api.factorio.com/latest/Classes.html:

vehicle_logistic_requests_enabled
:: boolean
[RW]

If personal logistic requests are enabled for this vehicle (spidertron).
Thanks, I know that, this actually works. I was interested in the other setting (the one marked with red). However, it occurred to me that it may work after all: To enabele vehicle_logistic_requests_enabled, I had to insert an item into the grid, and then switch over to the logistics tab. When I activated request_from_buffer_chests from my own GUI, the state of the checkbox on the spider-tron's GUI didn't change. That may have been because I didn't update the display. But I can't test that right now -- not at the computer with Factorio. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Spider-vehicle: How do I set "Request from buffer chests?"

Post by mrvn »

Ah, sorry. I was confused because you already had the only other thing related to the logistic requests in the spidertron in the question.

But you might be right that you actually just have to close and reopen the GUI to see any changes made by scripts.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1758
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Spider-vehicle: How do I set "Request from buffer chests?"

Post by Pi-C »

mrvn wrote: Tue Sep 13, 2022 12:43 am Ah, sorry. I was confused because you already had the only other thing related to the logistic requests in the spidertron in the question.
No problem!
But you might be right that you actually just have to close and reopen the GUI to see any changes made by scripts.
That worked! Too bad we can't auto-update the display. Closing and reopening the GUI has no effect when it's done on the same tick, and reopening the GUI on the next tick comes with a bit of overhead: store open GUI of player, then check all players in on_tick if they have a GUI to reopen.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Spider-vehicle: How do I set "Request from buffer chests?"

Post by mrvn »

Pi-C wrote: Tue Sep 13, 2022 9:35 pm
mrvn wrote: Tue Sep 13, 2022 12:43 am Ah, sorry. I was confused because you already had the only other thing related to the logistic requests in the spidertron in the question.
No problem!
But you might be right that you actually just have to close and reopen the GUI to see any changes made by scripts.
That worked! Too bad we can't auto-update the display. Closing and reopening the GUI has no effect when it's done on the same tick, and reopening the GUI on the next tick comes with a bit of overhead: store open GUI of player, then check all players in on_tick if they have a GUI to reopen.
You can register an event for 1 tick later so it's no overhead unless a GUI was closed. How often are you going to toggle this?
Pi-C
Smart Inserter
Smart Inserter
Posts: 1758
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Spider-vehicle: How do I set "Request from buffer chests?"

Post by Pi-C »

mrvn wrote: Wed Sep 14, 2022 12:10 am
Pi-C wrote: Tue Sep 13, 2022 9:35 pm Too bad we can't auto-update the display. Closing and reopening the GUI has no effect when it's done on the same tick, and reopening the GUI on the next tick comes with a bit of overhead: store open GUI of player, then check all players in on_tick if they have a GUI to reopen.
You can register an event for 1 tick later so it's no overhead unless a GUI was closed. How often are you going to toggle this?
Autodrive already checks the vehicles it's managing on every tick, skipping expensive things like charting most of the time:

Code: Select all

  -- tick_distributor =   vehicle.unit_number % 6
  local tick = game.tick + state.tick_distributor

  local cron_fuel       = (tick % 360 == 0)
  local cron_chart      = (tick % 300 == 0)
  local cron_ammo       = (tick % 180 == 0)
  local cron_circuit    = (tick % 60 == 0)

  local cron_enemy      = state.panic or (tick % 30 == 0)
  local cron_logistic   = (tick % 30 == 0)
  local cron_follow     = (tick % 30 == 0)
While the currently available version of the mod only supports "car"-based prototypes, my WIP version also has support for "spider-vehicle" prototypes. Now, some of the features Autodrive offers when one of its special "sensors" is added to a vehicle grid are natively supported by spider-vehicles (e.g. vehicle logistics, including a "request from buffer chests" checkbox). While I try to utilize as many of the native features as possible by calling different functions based on vehicle.type, there are some cases where I want to emulate the old behavior. For example, DMV makes a spider-vehicle version for each car prototype, and changes the result of all recipes producing cars to the new spider-vehicle version. So, if a player selects a vehicle based on a spider-vehicle prototype, I deactivate logistics for that vehicle unless it is equipped with a logistics sensor.

"Request from buffer chests" can be set from my mod's GUI, and it should be in sync with the state of the vehicle's checkbox. When vehicle.request_from_buffers is different from what the GUI says, I'll overwrite the vehicle's checkbox state. Unfortunately, there's no way to find out when the vehicle's checkbox is changed, so my idea was to use

Code: Select all

if vehicle.request_from_buffers ~= state.request_from_buffers then
  vehicle.request_from_buffers = state.request_from_buffers or false

  if player.opened == vehicle then
    player_data.re_open = vehicle
    player.opened = nil
  end
end
and run

Code: Select all

if player_data.re_open then
  player.opened = player_data.re_open
  player_data.re_open = nil
end
on the next tick. This really isn't too much code to add -- however, it will raise two events (on_gui_closed and on_gui_opened) and this could cause considerable overhead!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Spider-vehicle: How do I set "Request from buffer chests?"

Post by mrvn »

I think you can ignore that. That fraction of time the player has the GUI opened and plays with the button compared to the rest is nothing. Unless you have a massive multiplayer game and all player decide to play with the checkbox at the same time it should be ok.
Post Reply

Return to “Modding help”