I have a problem I always get "bad argument" when I use this code. I'll upload a picture. https://picload.org/view/ddapiwoi/errormsg.png.html
with version 0.15 the code always works but unfortunately it does not support the new 0.16 version.
mod url https://1drv.ms/u/s!AuM_LnCEkdcWyjYgNefF7E4p_QBC
Code: Select all
require "util"
script.on_event(defines.events.on_tick, function(event)
surface = game.surfaces[1]
if global.wind_turbine == nil then
global.wind_turbine = {}
global.wind_prev = surface.wind_speed
global.wind_next = surface.wind_speed
end
if (game.tick % 2500) == 0 then
global.wind_prev = global.wind_next
global.wind_next = math.random(25,40)/1000
end
if (game.tick % 125) == 0 then
local t = (game.tick % 2500) / 2500.0
surface.wind_speed = global.wind_prev + (global.wind_next-global.wind_prev) * t * t * (3.0 - 2.0 * t)
for key,wind_turbine in pairs(global.wind_turbine) do
if wind_turbine.valid then
wind_turbine.fluidbox [1]= {type="steam", icon_size=32, amount=150, temperature=(surface.wind_speed*2500)}
else
table.remove(global.wind_turbine, key)
end
end
end
end)
function on_creation(event)
if event.created_entity.name == "wind-turbine" then
local wind_turbine = event.created_entity
table.insert(global.wind_turbine, wind_turbine)
end
end
script.on_event(defines.events.on_built_entity, on_creation)
script.on_event(defines.events.on_robot_built_entity, on_creation)