minetest.get_perlin() and minetest.get_perlin_map() Return nil

prestidigitator
Member
 
Posts: 640
Joined: Thu Feb 21, 2013 23:54

minetest.get_perlin() and minetest.get_perlin_map() Return nil

by prestidigitator » Thu Jan 02, 2014 01:45

The minetest.get_perlin() function returns nil in 0.4.8 (haven't tried other versions). The minetest.get_perlin_map() function, which is barely mentioned in lua_api.txt and not documented anywhere on the wiki, also returns nil in this version.

The PerlinNoise() constructor does return a valid object, on the other hand, as does the PerlinNoiseMap() constructor (which is not documented in the wiki).

There seem to be no notes in lua_api.txt or the wiki about any of these functions being deprecated or replaced, and without digging through Git history logs or source code it is impossible to tell the intent and thus whether it is the implementation or the documentation that needs to be fixed.

Running Ubuntu 13.10 with the minetestc55 0.4.8-0ppa1~ubuntu13.10.1 package installed through the stable apt repo, though I suspect there is nothing platform specific about this behavior.
 

prestidigitator
Member
 
Posts: 640
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Thu Jan 02, 2014 01:56

Here is Lua code that can show the symptoms:

Code: Select all
local NOISE_PARAMS =
   {
      offset = 0,
      scale = 1,
      spread = { x = 100, y = 100, z = 100 },
      seed = 23,
      octaves = 3,
      persist = 0.70
   };
local SIZE = { x = 100, y = 100, z = 100 };


local function logResult(context, obj)
   local msg = (obj and "good") or "nil";
   minetest.log("error", context.." returned "..msg.." object");
end

logResult("get_perlin", minetest.get_perlin(1, 2, 0.5, 100));

logResult("get_perlin_map", minetest.get_perlin_map(NOISE_PARAMS, SIZE));

logResult("PerlinNoise", PerlinNoise(23, 3, 0.70, 100));

logResult("PerlinNoiseMap", PerlinNoiseMap(NOISE_PARAMS, SIZE));


The expected output is:

Code: Select all
17:53:56: ERROR[main]: get_perlin returned good object
17:53:56: ERROR[main]: get_perlin_map returned good object
17:53:56: ERROR[main]: PerlinNoise returned good object
17:53:56: ERROR[main]: PerlinNoiseMap returned good object


but the observed output is:

Code: Select all
17:53:56: ERROR[main]: get_perlin returned nil object
17:53:56: ERROR[main]: get_perlin_map returned nil object
17:53:56: ERROR[main]: PerlinNoise returned good object
17:53:56: ERROR[main]: PerlinNoiseMap returned good object
Last edited by prestidigitator on Thu Jan 02, 2014 01:57, edited 1 time in total.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Thu Jan 02, 2014 01:59

The code for get_perlin() wasnt touched since 0.4.7, and it doesnt return nil for me.

EDIT: Ah, found your problem: You can only call it after the environment is created. So put the code in minetest.after(0, ...) or so.
Last edited by PilzAdam on Thu Jan 02, 2014 02:01, edited 1 time in total.
 

prestidigitator
Member
 
Posts: 640
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Thu Jan 02, 2014 05:09

Ah. I see. And the two that were returning nil depend on the world's seed, whereas the constructors do not. Okay. Makes sense. Thank you.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Thu Jan 02, 2014 15:08

Hybrid Dog wrote:
PilzAdam wrote:EDIT: Ah, found your problem: You can only call it after the environment is created. So put the code in minetest.after(0, ...) or so.
like minetest.get_modpath()

In get_modpath() its exactly the other way round (IIRC), it only works the first time the modcode runs.
 


Return to Problems



Who is online

Users browsing this forum: No registered users and 3 guests