How to take actions when map blocks generate?

Place to get help with not working mods / modding interface.
Post Reply
BinaryMan
Inserter
Inserter
Posts: 21
Joined: Mon Mar 24, 2014 12:02 am
Contact:

How to take actions when map blocks generate?

Post 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?

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

Re: How to take actions when map blocks generate?

Post 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.

SirRichie
Fast Inserter
Fast Inserter
Posts: 244
Joined: Wed Feb 25, 2015 4:50 pm
Contact:

Re: How to take actions when map blocks generate?

Post 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

Post Reply

Return to “Modding help”