Page 2 of 2

Re: [MOD 0.12.x] Wind Turbine

Posted: Fri Oct 16, 2015 4:19 pm
by hrompik
error atfer update to Game version 0.12.11.
__Wind_Turbine__/control.lua:6: attempt to index global 'game' (a nil value)
When start new game, or load save.
- Lua API calls on_load, on_init, on_configuration_changed, on_event and generate_event_name
have been moved to a new namespace called script (so from now use script.on_load(...)). This will break many mods!
Just rename game.on_event to script.on_event
at 6 25 39 lines in control.lua

works!

Re: [MOD 0.12.x] Wind Turbine

Posted: Fri Oct 16, 2015 4:24 pm
by reddutton
i belive this is the case for most mods on the .11 update

Re: [MOD 0.12.x] Wind Turbine

Posted: Fri Oct 16, 2015 5:00 pm
by Keks
would it be possible, not extreme Lag causing and not a total pain for you to code:
  • change the momentary output for turbines that are far away (since wind conditions differ over distance ;))
  • Increase yield near Water
  • maybe create a version to place on water
  • or one that can only be placed the way offshore pumps are
thanks a lot btw ;)

Re: [MOD 0.12.11+] Wind Turbine

Posted: Fri Oct 16, 2015 7:45 pm
by Klonan
Mod has been updated for 0.12.11+

Please let me know if there are any bugs, errors etc.

Re: [MOD 0.12.11+] Wind Turbine

Posted: Sun Jan 10, 2016 7:33 pm
by SPolygon
Ehm, I have like 300 of theese guys powering my factory, but they all rotate in EXACTLY same way, so, is it possible to make each one rotate differently? I know, not a bug or anything, but still :D

Btw.: What about some larger version of it, that would require research and stuff?

Re: [MOD 0.12.x] Wind Turbine

Posted: Mon Jan 11, 2016 1:09 am
by Ranakastrasz
Keks wrote:would it be possible, not extreme Lag causing and not a total pain for you to code:
  • change the momentary output for turbines that are far away (since wind conditions differ over distance ;))
  • Increase yield near Water
  • maybe create a version to place on water
  • or one that can only be placed the way offshore pumps are
thanks a lot btw ;)
Locational power is feasible, but might be costly. As is, I imagine it runs a single pass setting the values for all of them. This would requires the equation to be run per entity, or per chunk.

Increased yield near water would be easy enough. On placement, attach data based on water proximity. If you have something like landfill installed however, might need to register such, or recalculate every half hour or something.

Placemet on water only. Probably possible to do, not sure how.
Offshore pumps. No idea how, but probably feasible, again.

Re: [MOD 0.12.11+] Wind Turbine

Posted: Wed Jan 13, 2016 11:07 am
by Klonan
SPolygon wrote:Ehm, I have like 300 of theese guys powering my factory, but they all rotate in EXACTLY same way, so, is it possible to make each one rotate differently? I know, not a bug or anything, but still :D

Btw.: What about some larger version of it, that would require research and stuff?
Yea that happens if you place the power poles down after you place the turbines, since they all connect at the same time, they all spin at the same time...
I suggest ripping them all up, and then placing them down after you have the power poles in place, this should help spread out the rotations

Re: [MOD 0.12.21] Wind Turbine

Posted: Thu May 05, 2016 12:26 am
by Afforess
I noticed the script update time for wind turbines was quite high with a lot of turbines placed, and took a peek at the code. There are a number of optimizations that can significantly cut the update time down (from 0.45 to 0.2 on my save), all in the check_generators function.

First, store data in local variables as much as possible, especially when a loop or iteration is involved. Even the tick can be stored in a variable. Previously you were making an API call to the game engine for each wind turbine just for the current tick, and then doing a modulus (sorta expensive), which can all be done once first and cached.

Also, there was a minor bug in the existing implementation that would cause wind turbines not to be updated for a tick when one was removed. When you iterate a list and are removing items in lua, you have to iterate it backwards. If you don't, and you call table.remove on an item, you will skip the next item in the list. This is because table.remove shifts every item down in the array when something is removed, so the next element is out of order in front-to-back iteration.

Full changes:

Code: Select all

function check_generators()
	if global.wind_turbine then
		local turbines = global.wind_turbine
		local num_turbines = #turbines
		local tick = game.tick % 125
		for k = num_turbines, 1, -1 do
			local gen = turbines[k]
			if k % 125 == tick then
				if gen.valid then
					local pot = gen.fluidbox[1]
		 			if pot then
						pot["amount"] = 10
						pot["temperature"] = 100*(game.wind_speed*25)
						gen.fluidbox[1] = pot
					else table.remove(turbines, k); end
				end
			end
		end
	end
end

Re: [MOD 0.12.21] Wind Turbine

Posted: Mon Sep 26, 2016 7:41 pm
by Shiny_Martin
Can I use this for my mod "Advanced Green Energy"?
Im doing upgrades to Solar Panels and a few more addons, and would really like to add Wind Turbines.

Re: [MOD 0.12.21] Wind Turbine

Posted: Mon Sep 26, 2016 7:43 pm
by Klonan
Shiny_Martin wrote:Can I use this for my mod "Advanced Green Energy"?
Im doing upgrades to Solar Panels and a few more addons, and would really like to add Wind Turbines.
Sure :)

Re: [MOD 0.12.21] Wind Turbine

Posted: Mon Sep 26, 2016 7:48 pm
by Shiny_Martin
Klonan wrote:
Shiny_Martin wrote:Can I use this for my mod "Advanced Green Energy"?
Im doing upgrades to Solar Panels and a few more addons, and would really like to add Wind Turbines.
Sure :)

Thanks! I will make sure to credit you. :D

Re: [MOD 0.12.21] Wind Turbine

Posted: Fri Jan 27, 2017 2:50 am
by Avocrom
I have hundreds of these things it's the only thing powering my buildings and except for a small spot all of them are now dead as the wind has stopped blowing.

Is this because I've removed most of the trees around me or is it just RNG? And what can if do, if anything, to fix this?

Thanks.

EDIT: And naturally I post the message and the wind starts blowing again.

Re: [MOD 0.12.21] Wind Turbine

Posted: Fri Dec 08, 2017 5:57 am
by PTTG
Does the wind vary depending on location? And how much?