Page 1 of 1

How to take actions when map blocks generate?

Posted: Tue Jun 09, 2015 1:00 am
by BinaryMan
I was looking at LUA/events for a hook. I saw: onchunkgenerated. It says "Contains area generated" but I'm not familiar with the data type. Does it contain tiles in the generated chunk or just coordinates of the chunk? Something like:

Code: Select all

require "defines"
 
 game.onevent(defines.events.onchunkgenerated, function(event)
    MakeResourcesInChunk(event.area)
 end) 
Will this event run for all the original chunks generated during map gen as well? Also, is there a better way to do debugging during runtime for multi-line scripts (so I don't have to keep reloading to test)? I heard about some god mode or test mode that might make it easier to test. LUA seems pretty flexible for this. For example in the above maybe I just want to dump the keys and values in the "event" object so I can see what's going on internally. Does the console accept multi-line input, and if so how?

Re: How to take actions when map blocks generate?

Posted: Tue Jun 09, 2015 7:12 am
by orzelek
I'd recommend looking at RSO. Dark coded nice logging system with file output there. It's triggered by save action or end of starting area resource generation.

The onchunkgenerated event is run for whole starting area - thats how RSO creates starting resources.

Re: How to take actions when map blocks generate?

Posted: Thu Jun 18, 2015 10:14 pm
by SirRichie
Having experimented with this myself, here are my findings (in line with orzelek's answer):

- onchunkgenerated runs once for every generated chunk, it does not re-run when you load a map
- the time when chunks are generated depends on what the player can see, chunks that the player newly discovered are generated with priority; however, if the player does not discover new places, chunks not yet visible get generated as well (in an area around the discovered area)

if you want to test scripts being triggered by some kind event, you can react to entity rotated events, then put a furnace somewhere (or have the script do it upon init) and "rotate" it, this way, you can deterministically trigger scripts