Copy link
@asl97

asl97 Apr 2, 2017

Contributor

@numberZero and what's wrong with that?
On the first run of that line, a new table would be assign to buffer.
every run after that would uses that table.

diff --git a/technic_worldgen/oregen.lua b/technic_worldgen/oregen.lua
index 41656c8..c35d347 100644
--- a/technic_worldgen/oregen.lua
+++ b/technic_worldgen/oregen.lua
@@ -116,7 +116,6 @@ minetest.register_ore({
 })
 
 -- Sulfur
-local sulfur_buf = nil
 local sulfur_noise= nil
 
 minetest.register_on_generated(function(minp, maxp, seed)
@@ -125,7 +124,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
                MinEdge = {x = emin.x, y = emin.y, z = emin.z},
                MaxEdge = {x = emax.x, y = emax.y, z = emax.z},
        }
-       local data = vm:get_data(sulfur_buf)
+       buffer = vm:get_data(buffer)
+       local data = buffer
+       print(data)
        local pr = PseudoRandom(17 * minp.x + 42 * minp.y + 101 * minp.z)
        sulfur_noise = sulfur_noise or minetest.get_perlin(9876, 3, 0.5, 100)

It works fine:

table: 0x40f2dba8
table: 0x40f2dba8
table: 0x40f2dba8
table: 0x40f2dba8

Just note that you can't use local inside the function on the buffer since that would cause it to get deleted when the function exited.

It should be possible to use local buffer outside the function in the global scope in the same place as local sulfur_buf.

Warning: I don't recommend not limiting the scope by not using local
ie: don't just use that patch as is in production.