<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.factorio.com/index.php?action=history&amp;feed=atom&amp;title=User%3ADarkfrei%2FSteam_Cooling</id>
	<title>User:Darkfrei/Steam Cooling - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.factorio.com/index.php?action=history&amp;feed=atom&amp;title=User%3ADarkfrei%2FSteam_Cooling"/>
	<link rel="alternate" type="text/html" href="https://wiki.factorio.com/index.php?title=User:Darkfrei/Steam_Cooling&amp;action=history"/>
	<updated>2026-10-02T03:47:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://wiki.factorio.com/index.php?title=User:Darkfrei/Steam_Cooling&amp;diff=177562&amp;oldid=prev</id>
		<title>Darkfrei: Created page with &quot;&lt;syntaxhighlight lang=&quot;lua&quot;&gt;  local supported_types = {&#039;storage-tank&#039;, &#039;pipe&#039;}  function is_value_in_table (value, tabl)   for i, v in pairs (tabl) do     if v == value then...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.factorio.com/index.php?title=User:Darkfrei/Steam_Cooling&amp;diff=177562&amp;oldid=prev"/>
		<updated>2020-02-16T16:51:52Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;  local supported_types = {&amp;#039;storage-tank&amp;#039;, &amp;#039;pipe&amp;#039;}  function is_value_in_table (value, tabl)   for i, v in pairs (tabl) do     if v == value then...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
local supported_types = {&amp;#039;storage-tank&amp;#039;, &amp;#039;pipe&amp;#039;}&lt;br /&gt;
&lt;br /&gt;
function is_value_in_table (value, tabl)&lt;br /&gt;
  for i, v in pairs (tabl) do&lt;br /&gt;
    if v == value then&lt;br /&gt;
      return true&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function cool_storage_tank (entity, dt)&lt;br /&gt;
  local fluidbox = entity.fluidbox&lt;br /&gt;
  if fluidbox then&lt;br /&gt;
    for i = 1, #fluidbox do&lt;br /&gt;
      local fluid = fluidbox[i]&lt;br /&gt;
      if fluid then&lt;br /&gt;
        local name = fluid.name&lt;br /&gt;
        local temp = fluid.temperature&lt;br /&gt;
        local amount = fluid.amount&lt;br /&gt;
        local min_temp = game.fluid_prototypes[name].default_temperature&lt;br /&gt;
        local delta_temp = (0.99 ^ (dt/amount)) * (temp-min_temp)&lt;br /&gt;
        &lt;br /&gt;
        fluid.temperature = min_temp + delta_temp&lt;br /&gt;
        fluidbox[i] = fluid -- why?&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function cool_pipe (entity, dt)&lt;br /&gt;
  local fluidbox = entity.fluidbox&lt;br /&gt;
  if fluidbox then&lt;br /&gt;
    for i = 1, #fluidbox do&lt;br /&gt;
      local fluid = fluidbox[i]&lt;br /&gt;
      if fluid then&lt;br /&gt;
        local name = fluid.name&lt;br /&gt;
        local temp = fluid.temperature&lt;br /&gt;
        local amount = fluid.amount&lt;br /&gt;
        local min_temp = game.fluid_prototypes[name].default_temperature&lt;br /&gt;
        local delta_temp = (0.99 ^ (dt/amount)) * (temp-min_temp)&lt;br /&gt;
        &lt;br /&gt;
        fluid.temperature = min_temp + delta_temp&lt;br /&gt;
        fluidbox[i] = fluid -- why?&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function main_handler (handler, dt) -- dt is time in ticks&lt;br /&gt;
  -- game.print (&amp;#039;ok: &amp;#039;..dt)&lt;br /&gt;
  local entity = handler.entity&lt;br /&gt;
  if entity and entity.valid then&lt;br /&gt;
    if entity.type == &amp;#039;storage-tank&amp;#039; then&lt;br /&gt;
      cool_storage_tank (entity, dt)&lt;br /&gt;
    elseif entity.type == &amp;#039;pipe&amp;#039; then&lt;br /&gt;
      cool_pipe (entity, dt)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    -- must be deleted&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function on_tick () -- I love this function / darkfrei&lt;br /&gt;
  -- multiple handlers per tick&lt;br /&gt;
  local handlers_per_tick = handlers_per_tick_global_setting or 1&lt;br /&gt;
  if not global.handlers then&lt;br /&gt;
    global.handlers = {}&lt;br /&gt;
    return -- nothing to do in this tick&lt;br /&gt;
  end&lt;br /&gt;
  local id = global.next_handler_id or 1&lt;br /&gt;
  local n = 0&lt;br /&gt;
  while n &amp;lt; handlers_per_tick do&lt;br /&gt;
    local handler = global.handlers[id+n]&lt;br /&gt;
    n = n + 1&lt;br /&gt;
    if handler then&lt;br /&gt;
      -- do the function&lt;br /&gt;
      -----&lt;br /&gt;
      local max_id = #global.handlers -- how many ticks it needs to update? It&amp;#039;s delta time!&lt;br /&gt;
      &lt;br /&gt;
      local valid = main_handler (handler, max_id/handlers_per_tick) -- returns false or nil if it was something wrong&lt;br /&gt;
      -----&lt;br /&gt;
      if not valid then&lt;br /&gt;
        &lt;br /&gt;
        if id &amp;lt; max_id then&lt;br /&gt;
          global.handlers[id] = global.handlers[max_id]&lt;br /&gt;
          global.handlers[max_id] = nil&lt;br /&gt;
        else -- id =&amp;gt; max_id; the last one&lt;br /&gt;
          global.handlers[id] = nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else -- no handler, earlier was the last one&lt;br /&gt;
      global.next_handler_id = 1&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  -- the next tick next handlers&lt;br /&gt;
  global.next_handler_id = id + n&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
script.on_event(defines.events.on_tick, on_tick)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function onBuildHandler (entity) &lt;br /&gt;
  local handler = {entity = entity}&lt;br /&gt;
  if not global.handlers then global.handlers = {} end&lt;br /&gt;
  table.insert(global.handlers, handler)&lt;br /&gt;
  game.print (#global.handlers)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
script.on_event(defines.events.on_built_entity, function(event)&lt;br /&gt;
  local entity_type = event.created_entity.type&lt;br /&gt;
  if is_value_in_table (entity_type, supported_types) then &lt;br /&gt;
    onBuildHandler (event.created_entity) &lt;br /&gt;
  end&lt;br /&gt;
end)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
script.on_event(defines.events.on_robot_built_entity, function(event)&lt;br /&gt;
  local entity_type = event.created_entity.type&lt;br /&gt;
  if is_value_in_table (entity_type, supported_types) then &lt;br /&gt;
    onBuildHandler (event.created_entity) &lt;br /&gt;
  end&lt;br /&gt;
end)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Darkfrei</name></author>
	</entry>
</feed>