News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

Is the factory energized?

Started by Yona-TYT, September 19, 2019, 03:15:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT


Hello how are you ?.

I have been working on a new chapter concerning the electrification of factories.

I would like a new function that allows me to know if the factory is being energized.

Example: factory_x.is_energized()

Dwachs

the best would be to check factory method get_pwer() to check whether something was consumed in the current and last months
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Quote from: Dwachs on September 20, 2019, 02:18:37 PM
the best would be to check factory method get_pwer() to check whether something was consumed in the current and last months
It looks fine.

But there is still a small problem that I still cannot solve, I need to know if the transformer of a factory is connected to the power plant (if there is electricity).

Is that possible?.
 

Dwachs

Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Apparently there is an error when the energy values of the current month are obtained, by some they return to "0" before the month ends.

Dwachs

the entry
  • is the current power supply/production. Entries with higher index are the sums of production / demand of previous months
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Quote from: Dwachs on September 21, 2019, 08:39:31 AMthe entry
  • is the current power supply/production. Entries with higher index are the sums of production / demand of previous months
I understand that the index "0" corresponds to the current month, the problem I see is that the value returns to "0" for some reason.

Look at this:
                    local f_list = [coord(36, 4), coord(95, 39), coord(76, 26)]
                    f_power = 0
                    for(local j=0;j<f_list.len();j++){
                        local tile = square_x(f_list[j].x, f_list[j].y).get_ground_tile()
                        local factory = tile.find_object(mo_building).get_factory()
                        if (factory){
                            local power = factory.get_power()[0]
                            f_power += power

                        }
                    }
                    gui.add_message(""+f_power+"")