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

Place to get help with not working mods / modding interface.
Post Reply
AngledLuffa
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

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

Post by AngledLuffa » Thu Feb 14, 2019 3:38 am

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!

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 1667
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

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

Post by darkfrei » Thu Feb 14, 2019 6:00 am

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?

AngledLuffa
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

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

Post by AngledLuffa » Thu Feb 14, 2019 6:07 am

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)

AngledLuffa
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

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

Post by AngledLuffa » Thu Feb 14, 2019 6:46 am

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)

User avatar
Bilka
Factorio Staff
Factorio Staff
Posts: 1154
Joined: Sat Aug 13, 2016 9:20 am
Contact:

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

Post by Bilka » Thu Feb 14, 2019 7:05 am

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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 1667
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

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

Post by darkfrei » Thu Feb 14, 2019 7:11 am

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.

AngledLuffa
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

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

Post by AngledLuffa » Thu Feb 14, 2019 8:26 am

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!

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: No registered users and 1 guest