I'd like to iterate over the beacons in my base to alert me to any that don't have any modules stored in them. However, looking at the specification for the beacon, I don't see any place to query the modules it has.
https://wiki.factorio.com/Prototype/Beacon
If I get a Beacon object in the console, how can I tell if it has 2 modules in it?
Thanks!
How to get modules stored in a beacon from the console?
-
- Fast Inserter
- Posts: 187
- Joined: Fri Jan 05, 2018 5:18 pm
- Contact:
Re: How to get modules stored in a beacon from the console?
See here:
https://lua-api.factorio.com/latest/Lua ... _inventory
So you are need to find all beacons, check if don't have full module inventory and than what? Spam marks to the map? Write the position of the nearest not-full beacon to the console?
https://lua-api.factorio.com/latest/Lua ... _inventory
So you are need to find all beacons, check if don't have full module inventory and than what? Spam marks to the map? Write the position of the nearest not-full beacon to the console?
-
- Fast Inserter
- Posts: 187
- Joined: Fri Jan 05, 2018 5:18 pm
- Contact:
Re: How to get modules stored in a beacon from the console?
Yep, spam marks to map, write down which train stations they are near, reload, go fix.
Thanks! Wasn't sure where to find the inventory. I haven't figured out why it doesn't show up in the Entity description here:
https://wiki.factorio.com/Prototype/Beacon
However, the method you linked works great:
Thanks! Wasn't sure where to find the inventory. I haven't figured out why it doesn't show up in the Entity description here:
https://wiki.factorio.com/Prototype/Beacon
However, the method you linked works great:
Code: Select all
/c local entity="beacon"
local surface=game.player.surface
local count=0
for key, ent in pairs(surface.find_entities_filtered({force=game.player.force})) do
if string.find(ent.name,entity) then
if ent.get_module_inventory().is_empty() then
game.player.force.add_chart_tag(ent.surface,{icon={type='virtual',name='signal-red'},position=ent.position,orientation=0.2})
count=count+1
end
end
end
game.player.print(count)
-
- Fast Inserter
- Posts: 187
- Joined: Fri Jan 05, 2018 5:18 pm
- Contact:
Re: How to get modules stored in a beacon from the console?
As an added bonus (and for posterity) here is a script which marks red all accumulators with more than half their charge. Best used when the other accumulators in the base are half used so that only the unattached accumulators are marked.
Code: Select all
/c local entity="accum"
local surface=game.player.surface
local count=0
for key, ent in pairs(surface.find_entities_filtered({force=game.player.force})) do
if string.find(ent.name,entity) then
if ent.energy>2500000 then
game.player.force.add_chart_tag(ent.surface,{icon={type='virtual',name='signal-red'},position=ent.position,orientation=0.2})
count=count+1
end
end
end
game.player.print(count)
Re: How to get modules stored in a beacon from the console?
Because prototypes are data phase. You are doing runtime scripting. These two phases of modding the game have completely separate lua apis.AngledLuffa wrote: ↑Thu Feb 14, 2019 6:07 amThanks! Wasn't sure where to find the inventory. I haven't figured out why it doesn't show up in the Entity description here:
https://wiki.factorio.com/Prototype/Beacon
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: How to get modules stored in a beacon from the console?
And if beacon is not empty then try to find map mark and if found then delete it.
If beacon is empty then check if here is mark before place it.
If beacon is empty then check if here is mark before place it.
-
- Fast Inserter
- Posts: 187
- Joined: Fri Jan 05, 2018 5:18 pm
- Contact:
Re: How to get modules stored in a beacon from the console?
Makes sense, I think - one is the definitions, the other is the actual objects. Thanks!Because prototypes are data phase. You are doing runtime scripting. These two phases of modding the game have completely separate lua apis.