How to know that a laboratory is working?

Place to get help with not working mods / modding interface.
Post Reply
suan2
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon May 22, 2017 1:41 pm
Contact:

How to know that a laboratory is working?

Post by suan2 »

I'm working on a mod to calculate the utilization of various buildings. I mean to calculate how many percentage of the last minute the building was "working". I found no universal flag for this, even though the game animates the buildings while they are working (i.e. the factory shows some moving parts, the drills are moving, the furnaces making fire, the laboratories shows sparkles, etc).

Here is what i found so far:
- assembling machines are working if is_crafting() returns true. Easy.
- furnaces are working is is_crafting() and crafting_progress < 1.0. Is there an easier way? is_crafting() stays true when the furnace is full, that's why i need to check the progress.
- mining-drills do not have is_mining() so i compare the mining_progress with the previous one and if it's not the same then the mining drill is working. This also sounds a bit complicated, is there an easier way?
- but i could not find anything for labs. How can i check if a lab is working? I found no attributes to get the progress, even though the game shows a progress bar.

Thanks for any ideas.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to know that a laboratory is working?

Post by prg »

Also not the most elegant way imaginable, but in line with what you're already doing there: maybe you could have a look at lab.get_inventory(defines.inventory.lab_input)[1 ... 7].durability and see if that changes over time.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

suan2
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon May 22, 2017 1:41 pm
Contact:

Re: How to know that a laboratory is working?

Post by suan2 »

Thanks for the tip. Unfortunately lab.get_inventory(defines.inventory.lab_input)[1 ... 7].durability doesn't seem to change.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to know that a laboratory is working?

Post by prg »

Code: Select all

inventory = game.player.selected.get_inventory(defines.inventory.lab_input)
script.on_event(defines.events.on_tick, function(event)
    print("tick " .. game.tick)
    for i = 1, 7 do
        local item = inventory[i]
        if item.valid_for_read then
            print(item.name .. ": " .. item.durability)
        end
    end
end)

Code: Select all

tick 294936
science-pack-1: 0.40111111111114
science-pack-2: 0.40111111111114
tick 294937
science-pack-1: 0.40055555555558
science-pack-2: 0.40055555555558
tick 294938
science-pack-1: 0.40000000000003
science-pack-2: 0.40000000000003
tick 294939
science-pack-1: 0.39944444444447
science-pack-2: 0.39944444444447
Works for me.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

suan2
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon May 22, 2017 1:41 pm
Contact:

Re: How to know that a laboratory is working?

Post by suan2 »

Thank you prg, that indeed works. I tried almost the same code and didn't work for me.

Post Reply

Return to “Modding help”