[0.12.35] area of event.on_chunk_generated is to big

Bugs that are actually features.
MrDoomah
Fast Inserter
Fast Inserter
Posts: 196
Joined: Mon Jun 01, 2015 1:11 pm
Contact:

[0.12.35] area of event.on_chunk_generated is to big

Post by MrDoomah »

The area returned by the on_chunk_generated event is to big. It returns an area as follows:

Code: Select all

area = {left_top = {x = n*32, y = m*32}, bottom_right = {x = (n+1)*32, y = (m+1)*32}}
where n and m are chunk coordinates. So for chunk position {0,0} it returns {{0,0},{32,32}}.
This is too big, as seen here:
Image

Returned area should be:

Code: Select all

area = {left_top = {x = n*32, y = m*32}, bottom_right = {x = n*32 + 31, y = m*32 + 31}}
Rseding91
Factorio Staff
Factorio Staff
Posts: 15903
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.12.35] area of event.on_chunk_generated is to big

Post by Rseding91 »

Your command is wrong. You're iterating from 0 to 32 inclusive which is 33 tiles total: 1 too many on both the x and y direction.

for x = 0,31 do is what you're looking for: the tiles in that chunk because they're 0 based indexing.

The "area" given during the chunk generated event is that - the *area* - not the tile size. The top left point is 0,0 and the bottom right point is 32,32: these are the chunks area and not tile sizes which is correct.
If you want to get ahold of me I'm almost always on Discord.
MrDoomah
Fast Inserter
Fast Inserter
Posts: 196
Joined: Mon Jun 01, 2015 1:11 pm
Contact:

Re: [0.12.35] area of event.on_chunk_generated is to big

Post by MrDoomah »

Rseding91 wrote:Your command is wrong. You're iterating from 0 to 32 inclusive which is 33 tiles total: 1 too many on both the x and y direction.

for x = 1,32 do is what you're looking for.
yah, fair point. It was a bad example.

To be more precise:
The area of a chunk is bounded by (in math notation)

Code: Select all

x = [n*32, (n+1)*32[
y = [m*32, (m+1)*32[
silverkitty23
Fast Inserter
Fast Inserter
Posts: 117
Joined: Wed May 11, 2016 6:52 am
Contact:

Re: [0.12.35] area of event.on_chunk_generated is to big

Post by silverkitty23 »

you're missing a little on the math notation: it's
x: n*32 (inclusive) => (n+1)*32 (exclusive)

I think the fn returns 0 and 32 because in C the loop wouldn't be : "for x = 0,32", it would be "for ( x = 0; x < 32; x++ )"
in other words, the function is correct for the internal API, and inconvenient for the Lua API :/
Post Reply

Return to “Not a bug”