[0.12]forces.chart method problem

Place to get help with not working mods / modding interface.
Scyth3
Burner Inserter
Burner Inserter
Posts: 9
Joined: Thu Jul 30, 2015 11:47 pm
Contact:

[0.12]forces.chart method problem

Post by Scyth3 »

I'm having some trouble understanding Lua tables. What I'm trying to do as a learning excercice is adding automatic charting to every chunk generated with the chunk generation event.

I'm using the Ore Expansion 1.0.1 mod as a base since I'm pretty new to Lua but so far I haven't managed to do so successfully as I'm getting "specified surface doesn't have a chart".

Could someone with some Lua experience give me a hand? I've tried the wiki and googling around but no luck so far.

Troublesome line is the last one.

Code: Select all

require "defines"

if not orexpmult then orexpmult = {} end


game.on_event(defines.events.on_chunk_generated, function(event)

	local distX = math.abs(event.area.left_top.x)
	local distY = math.abs(event.area.left_top.y)
	local mult = 1 + (math.floor(math.sqrt((distX * distX) + (distY * distY))) / 1024)
	orexpmult = mult
	--game.player.print(distX)
	--game.player.print(distY)
	--game.player.print(orexpmult)

	if mult > 1 then
		for _,ore in pairs(event.surface.find_entities_filtered({area = {{event.area.left_top.x, event.area.left_top.y}, {event.area.right_bottom.x, event.area.right_bottom.y}}, type="resource"})) do
			ore.amount = math.floor(ore.amount * mult)
		end
	end

	game.forces.player.chart(event.surface,{lefttop = {x = event.area.left_top.x, y = event.area.left_top.y}, rightbottom = {x = event.area.right_bottom.x, y = event.area.right_bottom.y}})

end)

orzelek
Smart Inserter
Smart Inserter
Posts: 3922
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: [0.12]forces.chart method problem

Post by orzelek »

No idea why it errors out.
But I think you are trying to do something strange in general. On chunk generated event is actually triggered by charting of the chunk in question.

Scyth3
Burner Inserter
Burner Inserter
Posts: 9
Joined: Thu Jul 30, 2015 11:47 pm
Contact:

Re: [0.12]forces.chart method problem

Post by Scyth3 »

No practical purpose just for science really. I'd just like both of them to go hand in hand.

My extremely wild guess is that chunks generate before the player spawns and because of this there is no player reference to chart to. Also changing

Code: Select all

game.forces.player.chart(event.surface,{lefttop = {x = event.area.left_top.x, y = event.area.left_top.y}, rightbottom = {x = event.area.right_bottom.x, y = event.area.right_bottom.y}})
to

Code: Select all

game.forces.player.chart(game.player.surface],{lefttop = {x = event.area.left_top.x, y = event.area.left_top.y}, rightbottom = {x = event.area.right_bottom.x, y = event.area.right_bottom.y}})
gives a similar error even though it works perfectly in the ingame console by manually replacing the x,y coordinates.

jorgenRe
Filter Inserter
Filter Inserter
Posts: 535
Joined: Wed Apr 09, 2014 3:32 pm
Contact:

Re: [0.12]forces.chart method problem

Post by jorgenRe »

I did trye out the:
game.on_event(defines.events.on_chunk_generated, function(event)
a few days ago, but i also ended up with an error so my guess was that something has changed with it due to the introduction of multiple surfaces(worlds) :/
Logo
Noticed the told change in FFF #111 so il continue to use my signature ^_^
Thanks for listening to our suggestions, devs :D!
I would jump of joy if we could specify which tiles spawned in a surfaces

jorgenRe
Filter Inserter
Filter Inserter
Posts: 535
Joined: Wed Apr 09, 2014 3:32 pm
Contact:

Re: [0.12]forces.chart method problem

Post by jorgenRe »

I did trye out the:
game.on_event(defines.events.on_chunk_generated, function(event)
a few days ago, but i also ended up with an error so my guess was that something has changed with it due to the introduction of multiple surfaces(worlds) :/
Logo
Noticed the told change in FFF #111 so il continue to use my signature ^_^
Thanks for listening to our suggestions, devs :D!
I would jump of joy if we could specify which tiles spawned in a surfaces

Post Reply

Return to “Modding help”