need help to fix wind turbine, 90% is done.

Place to get help with not working mods / modding interface.
User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

need help to fix wind turbine, 90% is done.

Post by unfunf22 »

hey hey
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)


Last edited by unfunf22 on Tue Jan 02, 2018 10:43 pm, edited 2 times in total.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: need help to fix wind turbine, 90% is done.

Post by darkfrei »

Can you attach whole mod?


chrisgbk
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Mon Jan 02, 2017 4:31 am
Contact:

Re: need help to fix wind turbine, 90% is done.

Post by chrisgbk »

unfunf22 wrote:hey hey
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)


Code: Select all

wind_turbine.fluidbox [1]= {type="steam", icon_size=32, amount=150, temperature=(surface.wind_speed*2500)}
icon_size is not a valid member of a fluidbox. "type" should be "name". API documentation here.

User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

Re: need help to fix wind turbine, 90% is done.

Post by unfunf22 »

thx my mod runs like version 0.15 now with 0.16

User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

Re: need help to fix wind turbine, 95% is done.

Post by unfunf22 »

hi thanks again for the help but I still have a little problem.
when I load a game with the mod it sometimes happens that my windturbine don't work and don't generate electricity.
is there a possibility to reload the windturbine entity when loading a game?
I think that would fix the problem that sometimes they don't work.
here is a controll code for my mod.

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 global.wind_turbine2 == nil then
        global.wind_turbine2 = {}
        global.wind_prev = surface.wind_speed
        global.wind_next = surface.wind_speed
    end
	
	if global.wind_turbine3 == nil then
        global.wind_turbine3 = {}
        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 - 1.5 * t)

        for key,wind_turbine in pairs(global.wind_turbine) do
            if wind_turbine.valid then
                wind_turbine.fluidbox [1]= {name="steam", amount=200, temperature=(surface.wind_speed*2500)}
            else
                table.remove(global.wind_turbine, key)
            end
		end
	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_turbine2 in pairs(global.wind_turbine2) do
            if wind_turbine2.valid then
                wind_turbine2.fluidbox [1]= {name="steam", amount=200, temperature=(surface.wind_speed*2500)}
            else
                table.remove(global.wind_turbine2, key)
            end
		end
	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 * (4.0 - 2.0 * t)

        for key,wind_turbine3 in pairs(global.wind_turbine3) do
            if wind_turbine3.valid then
                wind_turbine3.fluidbox [1]= {name="steam", amount=400, temperature=(surface.wind_speed*2500)}
            else
                table.remove(global.wind_turbine3, 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
	if event.created_entity.name == "wind-turbine2" then
        local wind_turbine2 = event.created_entity
        table.insert(global.wind_turbine2, wind_turbine2)
    end
	if event.created_entity.name == "wind-turbine3" then
        local wind_turbine3 = event.created_entity
        table.insert(global.wind_turbine3, wind_turbine3)
    end
	
end

script.on_event(defines.events.on_built_entity, on_creation)
script.on_event(defines.events.on_robot_built_entity, on_creation)

chrisgbk
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Mon Jan 02, 2017 4:31 am
Contact:

Re: need help to fix wind turbine, 95% is done.

Post by chrisgbk »

unfunf22 wrote:hi thanks again for the help but I still have a little problem.
when I load a game with the mod it sometimes happens that my windturbine don't work and don't generate electricity.
is there a possibility to reload the windturbine entity when loading a game?
I think that would fix the problem that sometimes they don't work.
here is a controll code for my mod.

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 global.wind_turbine2 == nil then
        global.wind_turbine2 = {}
        global.wind_prev = surface.wind_speed
        global.wind_next = surface.wind_speed
    end
	
	if global.wind_turbine3 == nil then
        global.wind_turbine3 = {}
        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 - 1.5 * t)

        for key,wind_turbine in pairs(global.wind_turbine) do
            if wind_turbine.valid then
                wind_turbine.fluidbox [1]= {name="steam", amount=200, temperature=(surface.wind_speed*2500)}
            else
                table.remove(global.wind_turbine, key)
            end
		end
	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_turbine2 in pairs(global.wind_turbine2) do
            if wind_turbine2.valid then
                wind_turbine2.fluidbox [1]= {name="steam", amount=200, temperature=(surface.wind_speed*2500)}
            else
                table.remove(global.wind_turbine2, key)
            end
		end
	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 * (4.0 - 2.0 * t)

        for key,wind_turbine3 in pairs(global.wind_turbine3) do
            if wind_turbine3.valid then
                wind_turbine3.fluidbox [1]= {name="steam", amount=400, temperature=(surface.wind_speed*2500)}
            else
                table.remove(global.wind_turbine3, 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
	if event.created_entity.name == "wind-turbine2" then
        local wind_turbine2 = event.created_entity
        table.insert(global.wind_turbine2, wind_turbine2)
    end
	if event.created_entity.name == "wind-turbine3" then
        local wind_turbine3 = event.created_entity
        table.insert(global.wind_turbine3, wind_turbine3)
    end
	
end

script.on_event(defines.events.on_built_entity, on_creation)
script.on_event(defines.events.on_robot_built_entity, on_creation)
It seems like it's possible for your script to try inserting steam that is below the minimum temperature to operate. If steam engines have steam that is too cold, they won't consume it, unlike previous versions. Steam has a minimum temperature of 100C to be used by steam engines.

In the prototype of your wind turbines, you can set fluid_box.minimum_temperature to 15, and ensure that the temperature of inserted steam has a minimum temperature of 15, which should operate like the old version. Probably needs more tweaking though.

User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

Re: need help to fix wind turbine, 90% is done.

Post by unfunf22 »

i think you misunderstood me a little bit.
it's not about the fact that my turbines need hot steam, but that my turbines sometimes don't want to work
anymore when i load the savegame and i have to tear them down and set them up again so that they go again.
i think a simple reload entity script could fix that problem. maybe one have an example code for that.

User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

Re: need help to fix wind turbine again.

Post by unfunf22 »

hi once again i need your help, unfortunately the mod doesn't work with the latest version. the wind turbine accepts steam but unfortunately it doesn't produce any. the previous code made this possible. now i don't know how to change the code to generate steam in the turbine again.
this is the new code that fixed some things up to 0.17 but now i need some help.

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 global.wind_turbine2 == nil then
        global.wind_turbine2 = {}
        global.wind_prev = surface.wind_speed
        global.wind_next = surface.wind_speed
    end
	
	if global.wind_turbine3 == nil then
        global.wind_turbine3 = {}
        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 * (4.0 - 3.0 * t)

        for key,wind_turbine in pairs(global.wind_turbine) do
            if wind_turbine.valid then
                wind_turbine.fluidbox [1]= {name="steam", amount=200, temperature=100}
            else
                table.remove(global.wind_turbine, key)
            end
		end
	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 * (4.0 - 2.0 * t)

        for key,wind_turbine2 in pairs(global.wind_turbine2) do
            if wind_turbine2.valid then
                wind_turbine2.fluidbox [1]= {name="steam", amount=200, temperature=100}
            else
                table.remove(global.wind_turbine2, key)
            end
		end
	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 * (5.0 - 2.0 * t)

        for key,wind_turbine3 in pairs(global.wind_turbine3) do
            if wind_turbine3.valid then
                wind_turbine3.fluidbox [1]= {name="steam", amount=200, temperature=100}
            else
                table.remove(global.wind_turbine3, 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
	if event.created_entity.name == "wind-turbine2" then
        local wind_turbine2 = event.created_entity
        table.insert(global.wind_turbine2, wind_turbine2)
    end
	if event.created_entity.name == "wind-turbine3" then
        local wind_turbine3 = event.created_entity
        table.insert(global.wind_turbine3, wind_turbine3)
    end
	
end

Honktown
Smart Inserter
Smart Inserter
Posts: 1037
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: need help to fix wind turbine, 90% is done.

Post by Honktown »

Name doesn't exist in fluidboxes:

https://lua-api.factorio.com/latest/LuaFluidBox.html

I don't know what changes have to be made to make old behavior act the same in new code. I only know name doesn't exist because an entity stopped working in a mod I'm working with for a different reason (how you can't connect mis-matched fluid systems in .17) - and that code had fluidbox.name as I was going over how the entity worked.
I have mods! I guess!
Link

User avatar
planetmaker
Fast Inserter
Fast Inserter
Posts: 188
Joined: Mon Jan 21, 2019 9:30 am
Contact:

Re: need help to fix wind turbine, 90% is done.

Post by planetmaker »

I wonder: why would a wind turbine need steam at all? The usual way they are built is to attach a generator directly (or via gears) to the rotators. So they should work more like solar cells - except in a globaly somewhat random fashion instead of day-night cycle.

User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

Re: need help to fix wind turbine, 90% is done.

Post by unfunf22 »

thanks for the advice, i looked at a similar mod and found a suitable solution.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: need help to fix wind turbine, 90% is done.

Post by darkfrei »

unfunf22 wrote:
Sat Feb 01, 2020 2:09 pm
thanks for the advice, i looked at a similar mod and found a suitable solution.
See also my Vertical Axis Wind Turbines, it uses the wind speed property that will be changed by the Wind Speed Changing.

Post Reply

Return to “Modding help”