## Post your modding questions here Hybrid Dog
Member

Posts: 2726
Joined: Thu Nov 01, 2012 12:46

### Re: Post your modding questions here

It doesn't work:
Code: Select all
`local function getb(d)   return math.log(2*d) / (1 - d)endlocal function geta(b)   return 1/(1-math.exp(-b))endlocal function v(d)   print("d = " .. d)   local b = getb(d)   print("b = " .. b)   local a = geta(b)   print("a = " .. a)   -- col should be 0.5   local col = a*(1-math.exp(-b*d))   print("col = " .. col)   return colendfor i = 0,10 do   v(i/10)   print("\r")end`

+ "col should be 0.5 because v(d) should be 0.5"

deriving is a nice idea but
call the left side l(b) and the right side r(b)
l(b) = r(b)
the derivation gives the pitch of the function, but l and r are just equal at b, which is fixed, so l'(b) doesn't need to be r'(b)

Maybe you need to use the W function to shift it for b

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪ Hybrid Dog
Member

Posts: 2726
Joined: Thu Nov 01, 2012 12:46

### Re: Post your modding questions here

l made it get b approximately:
Code: Select all
`local function geta(b)   return 1/(1-math.exp(-b))endlocal minb = -1002local maxb = 30001local function v(d)   local b   io.write("d = " .. d.."\n")   for i = 0,100 do      b = (minb+maxb)/2      io.write("b = " .. b.."; ")      local a = geta(b)      --print("a = " .. a)      local col = a*(1-math.exp(-b*d))      io.write("col = " .. col.."\n")      if math.log(col-0.5)/math.log(10) < -9      or tostring(col) == "nan" then         break      elseif col < 0.5 then         minb = b      else         maxb = b      end   endendv(0.8)`

+ "the result"

This makes a list of bs:
Code: Select all
`local function geta(b)   return 1/(1-math.exp(-b))endlocal function v(d)   local minb = -1002   local maxb = 30001   local b   --io.write("d = " .. d.."\n")   for i = 0,100 do      b = (minb+maxb)/2      --io.write("b = " .. b.."; ")      local a = geta(b)      --print("a = " .. a)      local col = a*(1-math.exp(-b*d))      --io.write("col = " .. col.."\n")      if math.log(col-0.5)/math.log(10) < -9      or tostring(col) == "nan" then         break      elseif col < 0.5 then         minb = b      else         maxb = b      end   end   return bendfor i = 0,10 do   local d = i/10   io.write("d = " .. d..";"..(" "):rep(5-#tostring(d)).."b = "..v(d).."\n")end`

To use it for automatic brightness adjusting, the bs can be stored in a table and to get a b, interpolation can be used
Code: Select all
`d = 0;    b = 30001d = 0.1;  b = 6.921614307927d = 0.2;  b = 3.2812798977898d = 0.3;  b = 1.8010717819961d = 0.4;  b = 0.82216324127785d = 0.5;  b = 9.4905772130005e-09d = 0.6;  b = -0.82216322934596d = 0.7;  b = -1.8010717700643d = 0.8;  b = -3.2812798929072d = 0.9;  b = -6.9216142889459d = 1;    b = -759.7890625`

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪ Hybrid Dog
Member

Posts: 2726
Joined: Thu Nov 01, 2012 12:46

### Re: Post your modding questions here

Code: Select all
`-- code including much unusedlocal load_time_start = os.clock()math.randomseed(os.time()+tonumber(io.popen("date +%N"):read("*all")))--\$ luajit parab.lua | pnmtopng > dsa.png && optipng -o7 -quiet dsa.pnglocal s = 2^10local col = 255local tab = {"P3", s, s, col}local num = 5local function info(msg)   os.execute("notify-send '"..msg.."'")endlocal function round(n)   return math.floor(n+0.5)endlocal function gcol(c)   if c == math.huge   or tostring(c) == "-nan" then      c = 0   end   return round(c)%(col+1)endlocal function set(r,g,b)   tab[num] = gcol(r)   tab[num+1] = gcol(g)   tab[num+2] = gcol(b)   num = num+3endlocal sts = {}local minc, maxclocal function tset(c)   if not minc then      minc = c      maxc = c   end   minc = math.min(c, minc)   maxc = math.max(c, maxc)   table.insert(sts, c)endlocal function geta(b)   return 1/(1-math.exp(-b))endlocal function v(d)   local minb = -1002   local maxb = 30001   local b   --io.write("d = " .. d.."\n")   for i = 0,100 do      b = (minb+maxb)/2      --io.write("b = " .. b.."; ")      local a = geta(b)      --print("a = " .. a)      local col = a*(1-math.exp(-b*d))      --io.write("col = " .. col.."\n")      if math.log(col-0.5)/math.log(10) < -9      or tostring(col) == "nan" then         break      elseif col < 0.5 then         minb = b      else         maxb = b      end   end   return bendlocal function f(x)   return v((x+s/2)/s)*s/100--math.sqrt(math.abs(10000-x*x))endlocal crds = {}local a,b = -s/2+1, s/2for x = a,b do   if x == 0 then      for y = a,b do         crds[y] = crds[y] or {}         crds[y][x] = 0.5      end   else      local yf = f(x)      if yf > b then         for y = a,b do            crds[y] = crds[y] or {}            crds[y][x] = 0         end      elseif yf < a then         for y = a,b do            crds[y] = crds[y] or {}            crds[y][x] = 1         end      else         for y = a,math.floor(yf) do            crds[y] = crds[y] or {}            crds[y][x] = 0         end         for y = math.ceil(yf),b do            crds[y] = crds[y] or {}            crds[y][x] = 1         end         local y = math.ceil(yf)         crds[y] = crds[y] or {}         crds[y][x] = math.max(0, math.min(1, y-yf))      end   endend-- [[for y = s/2,-s/2+1,-1 do   for x = 1,s do      x = x-s/2      tset(crds[y][x])   endend--]]--[[for x = 1,s do   x = x-1--s/2   tset(do_ws_func(2, x))end--]]--[[local crn = {x1=0,y1=0, x2=0,y2=0}local hs = {}local function seth(x,y)   if not hs[y] then      hs[y] = {}   end   if not hs[y][x] then      hs[y][x] = 1   else      hs[y][x] = hs[y][x]+1   end   crn.x1 = math.min(x, crn.x1)   crn.y1 = math.min(y, crn.y1)   crn.x2 = math.max(x, crn.x2)   crn.y2 = math.max(y, crn.y2)endlocal function geth(x,y)   if not hs[y] then      return 0   end   return hs[y][x] or 0endlocal cx = 0local cy = 0local dirs = {   {1,0},   {0,1},   {-1,0},   {0,-1},}local dif = maxc-mincfor i = 1,#sts do   local v = sts[i]   v = (v-minc)/dif   sts[i] = v   -- [ [   v = v*255   v = v*math.pi   set(v,v,v)-- ] ]   seth(cx,cy)   --info(round(v*3)+1)   --local dir = (v*300)%1   local dir = (round(v*math.pi*100))%4+1   local ndir = dirs[dir]   cx = cx+ndir   cy = cy+ndirendcrn.x1 = crn.x1-5crn.y1 = crn.y1-5crn.x2 = crn.x2+5crn.y2 = crn.y2+5local s = {crn.x2-crn.x1, crn.y2-crn.y1}tab = s+1tab = s+1maxc = 0for y,xs in pairs(hs) do   for _,h in pairs(xs) do      maxc = math.max(maxc, h)   endendfor y = crn.y1,crn.y2 do   for x = crn.x1,crn.x2 do      local c = 0      local v = hs[y]      if v then         c = hs[y][x] or 0      end      c = c*255/maxc      --c = c%2*255      set(c,c,c)   endend--]]local dif = maxc-mincfor i = 1,#sts do   local v = sts[i]   v = (v-minc)/dif   --sts[i] = v   -- [[   v = v*255   --v = v*math.pi   set(v,v,v)--]]   --[[   seth(cx,cy)   --info(round(v*3)+1)   --local dir = (v*300)%1   local dir = (round(v*math.pi*100))%4+1   local ndir = dirs[dir]   cx = cx+ndir   cy = cy+ndir--]]endinfo("fi")print(table.concat(tab, " "))local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100local msg = "fertig nach ca. "..time.."s"if time > 0.05 then   info(msg)end`

l think 1 y is 50 x on the picture Attachments dsa.png

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪ iangp
Member

Posts: 114
Joined: Sat May 31, 2014 19:26
Location: Brasil - ES
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

### Re: Post your modding questions here

Well, nice results for your approximation :D

I just had this idea cause the (-1) was pissing me off after a while trying shift the equation hehe and d/dx(constant) = 0, a perfect murder hehe, unfortunately doesn't work in this case.

I just learned Calculus I (limits, derivatives and integrals, with just one variable and at IR) and I need more practice, but I'll try understand W function in somewhere else.
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP): Hybrid Dog
Member

Posts: 2726
Joined: Thu Nov 01, 2012 12:46

### Re: Post your modding questions here

l didn't know derivations with more than one variable are possible.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪ iangp
Member

Posts: 114
Joined: Sat May 31, 2014 19:26
Location: Brasil - ES
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

### Re: Post your modding questions here

partial derivatives of functions that have more than one variable.
https://en.wikipedia.org/wiki/Partial_derivative
And derivatives of vectors, I see that like "more than one variable" (in this case axis), gradient and others operations

the point is I'm just getting started at this new stage of mathematics :P
This is probably getting off-topic it's better we finish it here.
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP): Foghrye4
Member

Posts: 24
Joined: Sun Mar 13, 2016 13:38
IRC: Foghrye4
In-game: Foghrye4

### Re: Post your modding questions here

I have a question!
I want to override ore generation of other mods. Thus i can use "minetest.clear_registered_ores()". But how i can control mod load order? Does it depends from mod name? paramat
Developer

Posts: 3555
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat
IRC: paramat

### Re: Post your modding questions here

the 'depends.txt' file controls mod order. Foghrye4
Member

Posts: 24
Joined: Sun Mar 13, 2016 13:38
IRC: Foghrye4
In-game: Foghrye4

### Re: Post your modding questions here

Thank, paramat. Hybrid Dog
Member

Posts: 2726
Joined: Thu Nov 01, 2012 12:46

### Re: Post your modding questions here

Do mesh objects have a cuboid collision box or a complex one?

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪ Don
Member

Posts: 1643
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

### Re: Post your modding questions here

You set the collision box like a nodebox.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!

A list of my mods can be found here xeranas
Member

Posts: 155
Joined: Fri Feb 05, 2016 11:06

### Re: Post your modding questions here

Hi,
I'm trying to create block similar to furnace but more like "item converter". Due this reason I cannot use regular "fuel" recipes (I want that items as "fuel" would work only on my block).

So far I decided go ABM route which would check item in "fuel" slot and add it as fuel time manually according some predefined rules. To do so I need "extract" fuel name from fuel slot (it will be multiple custom "fuels").

I take furnace as example
Code: Select all
`minetest.register_abm({  action = function(pos, node, active_object_count, active_object_count_wider)    local meta = minetest.get_meta(pos)    local inv = meta:get_inventory()    local fuellist = inv:get_list("fuel")`

Seems I getting list of userdata objects. I do not know how to extract properties from them rather than guessing. Unfortunately minetest dev wiki and lua api documentation does not provide explanation about userdata (or I missed?).
Code: Select all
`{ <userdata 1> }`

Maybe I did completely wrong and I need go another direction? xeranas
Member

Posts: 155
Joined: Fri Feb 05, 2016 11:06

### Re: Post your modding questions here

guessing over
Code: Select all
`userdata:get_name()`

Still where I could find which properties I can get from userdata? Maybe we can add some notes in dev wiki or lua api to help newbies like me?

Byakuren
Member

Posts: 816
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

### Re: Post your modding questions here

They are a list of ItemStack. You can find the methods available in the mod API doc.
Every time a mod API is left undocumented, a koala dies. xeranas
Member

Posts: 155
Joined: Fri Feb 05, 2016 11:06

### Re: Post your modding questions here

Byakuren wrote:They are a list of ItemStack. You can find the methods available in the mod API doc.

Thanks!, I was bit confused because lua.api documentation does not explicity says which type of objects from list I should expect. InvRef get_list
get_list(listname): return full list garywhite
Member

Posts: 109
Joined: Fri Feb 12, 2016 16:19
Location: San Francisco, CA
GitHub: garywhite207
IRC: same as MT name
In-game: garywhite garywhite1

### Re: Post your modding questions here

I am trying to set up a server, but I cannot get unified_inventory to work. Attached is the in-game load error.

Here is what debug says:
Code: Select all
`2016-03-17 10:44:46: ERROR[main]: Failed to load and run script from 2016-03-17 10:44:46: ERROR[main]: D:\FlipShare Data\mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua:2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:60: Name unified_inventory:bag_small does not follow naming conventions: "modname:" or ":" prefix required2016-03-17 10:44:46: ERROR[main]: stack traceback:2016-03-17 10:44:46: ERROR[main]:    [C]: in function 'error'`

Does anyone know? I tried installing bags mod, to no avail. Please reply.

garywhite mt error.png

Code: Select all
`2016-03-17 10:44:46: ERROR[main]:    ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:60: in function 'check_modname_prefix'2016-03-17 10:44:46: ERROR[main]:    ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:98: in function 'register_item'2016-03-17 10:44:46: ERROR[main]:    ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:216: in function 'really_register_tool'2016-03-17 10:44:46: ERROR[main]:    ...t-0.4.13\bin\..\mods\Technic\technic_worldgen/crafts.lua:162: in function 'register_tool'2016-03-17 10:44:46: ERROR[main]:    ...mt\minetest-0.4.13\bin\..\mods\unifiedinventory/bags.lua:173: in main chunk2016-03-17 10:44:46: ERROR[main]:    [C]: in function 'dofile'2016-03-17 10:44:46: ERROR[main]:    ...mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua:63: in main chunk2016-03-17 10:44:46: ERROR[main]: ======= END OF ERROR FROM LUA ========2016-03-17 10:44:46: ERROR[main]: Server: Failed to load and run D:\FlipShare Data\mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua2016-03-17 10:44:46: ERROR[main]: ModError: ModError: Failed to load and run D:\FlipShare Data\mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua2016-03-17 10:44:46: ERROR[main]: Error from Lua:2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:60: Name unified_inventory:bag_small does not follow naming conventions: "modname:" or ":" prefix required2016-03-17 10:44:46: ERROR[main]: stack traceback:2016-03-17 10:44:46: ERROR[main]:    [C]: in function 'error'2016-03-17 10:44:46: ERROR[main]:    ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:60: in function 'check_modname_prefix'2016-03-17 10:44:46: ERROR[main]:    ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:98: in function 'register_item'2016-03-17 10:44:46: ERROR[main]:    ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:216: in function 'really_register_tool'2016-03-17 10:44:46: ERROR[main]:    ...t-0.4.13\bin\..\mods\Technic\technic_worldgen/crafts.lua:162: in function 'register_tool'2016-03-17 10:44:46: ERROR[main]:    ...mt\minetest-0.4.13\bin\..\mods\unifiedinventory/bags.lua:173: in main chunk2016-03-17 10:44:46: ERROR[main]:    [C]: in function 'dofile'2016-03-17 10:44:46: ERROR[main]:    ...mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua:63: in main chunk2016-03-17 10:44:46: ERROR[main]: Check debug.txt for details.` Hybrid Dog
Member

Posts: 2726
Joined: Thu Nov 01, 2012 12:46

### Re: Post your modding questions here

you called the mod folder unifiedinventory, but you need to call it unified_inventory

http://wiki.minetest.net/Troubleshootin ... a.E2.80.9D

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪ BrunoMine
Member

Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

### Re: Post your modding questions here

Code: Select all
`minetest.register_decoration()`

How I can set a quantity of generated items? MineYoshi
Member

Posts: 5373
Joined: Wed Jul 08, 2015 13:20

### Re: Post your modding questions here

Exactly how i can stop this function with other use?

Code: Select all
`minetest.register_tool("headphones:1headphones", {   description = "Headphones Test Song",   inventory_image = "testh.bmp",   on_use = function()      minetest.sound_play("test")   end,         })`

I mean i click one time, plays the sound, i click other time, the song plays again with the other.
I want to do this, i click one time, plays the sound, i click again and the stops the sound, how i do that?
Happy new Year 2020: let's all aim finally for a clear vision of what we want to make of Minetest! iangp
Member

Posts: 114
Joined: Sat May 31, 2014 19:26
Location: Brasil - ES
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

### Re: Post your modding questions here

MineYoshi wrote:Exactly how i can stop this function with other use?

Code: Select all
`minetest.register_tool("headphones:1headphones", {   description = "Headphones Test Song",   inventory_image = "testh.bmp",   on_use = function()      minetest.sound_play("test")   end,         })`

I mean i click one time, plays the sound, i click other time, the song plays again with the other.
I want to do this, i click one time, plays the sound, i click again and the stops the sound, how i do that?

What if you:
Code: Select all
`--Put a global var heresound = 'no'minetest.register_tool("headphones:1headphones", {   description = "Headphones Test Song",   inventory_image = "testh.bmp",   on_use = function()        if sound == 'no' then            sound = minetest.sound_play("test") --keep the "reference" of the sound        else            minestes.sound_stop(sound)           sound = 'no'       end   end,         })`
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):

Byakuren
Member

Posts: 816
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

### Re: Post your modding questions here

Except you probably want to make sound a local var instead.
Every time a mod API is left undocumented, a koala dies. rubenwardy
Moderator

Posts: 5965
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

### Re: Post your modding questions here

You should rarely use global variables as they will be present in other mods. You should only create global variables with the same name as your mod. Hybrid Dog
Member

Posts: 2726
Joined: Thu Nov 01, 2012 12:46

### Re: Post your modding questions here

VaE adds a vector.dot and people may think it's added by builtin, so they don't notice that their mod crashes if pipeworks isn't installed

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪ iangp
Member

Posts: 114
Joined: Sat May 31, 2014 19:26
Location: Brasil - ES
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

### Re: Post your modding questions here

rubenwardy wrote:You should rarely use global variables as they will be present in other mods. You should only create global variables with the same name as your mod.

hmm This is a convention ? I understand the fact, avoid using global vars, because they can conflict with other mods but if I use something like that, would it be ok?:
nameofmymod_sound = 'no'
or local sound = 'no' also works inside the func?

another Q: This is documented on wiki or on somewhere?, I'm just can't remember...
That was just a "speed coding"...
Reading this I think I should review some code on my mods... XD
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP): rubenwardy
Moderator

Posts: 5965
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

### Re: Post your modding questions here

It's just good practice not to. Instead of nameofmymod_sound you should do nameofmymod.sound or a local variable.
Global variables are the best way to communicate between files. The alternative is passing parameters between files is a bit weird.

Code: Select all
`-- You can do this if you want want to make a global variable,-- but I usually use nameofmod.sound as I prefer that personally.local sound = "no"dofile(minetest.get_modpath() .. "/other.lua", sound)`

This doesn't seem to be mentioned anyway, except a little bit by me here: http://rubenwardy.com/minetest_modding_ ... and-global

PreviousNext 