Page 1 of 1
Spider-vehicle: How do I set "Request from buffer chests?"
Posted: Mon Sep 12, 2022 8:45 pm
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 (61.09 KiB) Viewed 1386 times
Re: Spider-vehicle: How do I set "Request from buffer chests?"
Posted: Mon Sep 12, 2022 9:09 pm
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).
Re: Spider-vehicle: How do I set "Request from buffer chests?"
Posted: Mon Sep 12, 2022 10:18 pm
by Pi-C
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.

Re: Spider-vehicle: How do I set "Request from buffer chests?"
Posted: Tue Sep 13, 2022 12:43 am
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.
Re: Spider-vehicle: How do I set "Request from buffer chests?"
Posted: Tue Sep 13, 2022 9:35 pm
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.
Re: Spider-vehicle: How do I set "Request from buffer chests?"
Posted: Wed Sep 14, 2022 12:10 am
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?
Re: Spider-vehicle: How do I set "Request from buffer chests?"
Posted: Wed Sep 14, 2022 10:53 am
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!
Re: Spider-vehicle: How do I set "Request from buffer chests?"
Posted: Wed Sep 14, 2022 11:12 am
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.