Page 1 of 1

How to get modules stored in a beacon from the console?

Posted: Thu Feb 14, 2019 3:38 am
by AngledLuffa
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!

Re: How to get modules stored in a beacon from the console?

Posted: Thu Feb 14, 2019 6:00 am
by darkfrei
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?

Re: How to get modules stored in a beacon from the console?

Posted: Thu Feb 14, 2019 6:07 am
by AngledLuffa
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:

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)

Re: How to get modules stored in a beacon from the console?

Posted: Thu Feb 14, 2019 6:46 am
by AngledLuffa
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?

Posted: Thu Feb 14, 2019 7:05 am
by Bilka
AngledLuffa wrote:
Thu Feb 14, 2019 6:07 am
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
Because prototypes are data phase. You are doing runtime scripting. These two phases of modding the game have completely separate lua apis.

Re: How to get modules stored in a beacon from the console?

Posted: Thu Feb 14, 2019 7:11 am
by darkfrei
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.

Re: How to get modules stored in a beacon from the console?

Posted: Thu Feb 14, 2019 8:26 am
by AngledLuffa
Because prototypes are data phase. You are doing runtime scripting. These two phases of modding the game have completely separate lua apis.
Makes sense, I think - one is the definitions, the other is the actual objects. Thanks!