Page 1 of 1

How to know that a laboratory is working?

Posted: Thu May 25, 2017 12:34 pm
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.

Re: How to know that a laboratory is working?

Posted: Thu May 25, 2017 3:24 pm
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.

Re: How to know that a laboratory is working?

Posted: Fri May 26, 2017 4:06 pm
by suan2
Thanks for the tip. Unfortunately lab.get_inventory(defines.inventory.lab_input)[1 ... 7].durability doesn't seem to change.

Re: How to know that a laboratory is working?

Posted: Fri May 26, 2017 4:18 pm
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.

Re: How to know that a laboratory is working?

Posted: Sat May 27, 2017 2:25 pm
by suan2
Thank you prg, that indeed works. I tried almost the same code and didn't work for me.