Post your modding questions here

User avatar
Hybrid Dog
Member
Posts: 2836
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

It doesn't work:

Code: Select all

local function getb(d)
	return math.log(2*d) / (1 - d)
end

local function geta(b)
	return 1/(1-math.exp(-b))
end

local 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 col
end

for i = 0,10 do
	v(i/10)
	print("\r")
end
Spoiler
d = 0
b = -inf
a = -0
col = nan

d = 0.1
b = -1.788264347149
a = -0.20084088574179
col = 0.039327291406572

d = 0.2
b = -1.1453634148427
a = -0.46650851967355
col = 0.12009488819587

d = 0.3
b = -0.72975089109427
a = -0.93061021188818
col = 0.22775591524473

d = 0.4
b = -0.37190591885702
a = -2.2197730208415
col = 0.3560453958317

d = 0.5
b = 0
a = inf
col = nan

d = 0.6
b = 0.45580389198489
a = 2.7317787610291
col = 0.65364424779417

d = 0.7
b = 1.1215741220707
a = 1.48316590624
col = 0.80673363750398

d = 0.8
b = 2.3500181462287
a = 1.1054211786931
col = 0.93674729278413

d = 0.9
b = 5.8778666490212
a = 1.0028086201511
col = 0.99775310387913

d = 1
b = inf
a = 1
col = 1
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

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
Hybrid Dog
Member
Posts: 2836
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

l made it get b approximately:

Code: Select all

local function geta(b)
	return 1/(1-math.exp(-b))
end

local minb = -1002
local maxb = 30001

local 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
	end
end

v(0.8)
Spoiler
d = 0.8
b = 14499.5; col = 1
b = 6748.75; col = 1
b = 2873.375; col = 1
b = 935.6875; col = 1
b = -33.15625; col = 0.0013185139131068
b = 451.265625; col = 1
b = 209.0546875; col = 1
b = 87.94921875; col = 1
b = 27.396484375; col = 0.99999999969823
b = -2.8798828125; col = 0.53611234532014
b = -18.01806640625; col = 0.02722515775512
b = -10.448974609375; col = 0.12368711017427
b = -6.6644287109375; col = 0.26277482855574
b = -4.7721557617188; col = 0.37978275468918
b = -3.8260192871094; col = 0.45332360670287
b = -3.3529510498047; col = 0.49369563299398
b = -3.1164169311523; col = 0.51467348487931
b = -3.2346839904785; col = 0.50412338618094
b = -3.2938175201416; col = 0.49889380994757
b = -3.2642507553101; col = 0.50150472233792
b = -3.2790341377258; col = 0.50019829096251
b = -3.2864258289337; col = 0.49954580588774
b = -3.2827299833298; col = 0.49987198737943
b = -3.2808820605278; col = 0.5000351239216
b = -3.2818060219288; col = 0.49995355183667
b = -3.2813440412283; col = 0.49999433692586
b = -3.281113050878; col = 0.50001473018543
b = -3.2812285460532; col = 0.50000453349607
b = -3.2812862936407; col = 0.49999943519607
b = -3.281257419847; col = 0.50000198434235
b = -3.2812718567438; col = 0.50000070976828
b = -3.2812790751923; col = 0.50000007248194
b = -3.2812826844165; col = 0.49999975383895
b = -3.2812808798044; col = 0.49999991316043
b = -3.2812799774983; col = 0.49999999282118
b = -3.2812795263453; col = 0.50000003265156
b = -3.2812797519218; col = 0.50000001273637
b = -3.2812798647101; col = 0.50000000277878
b = -3.2812799211042; col = 0.49999999779998
b = -3.2812798929072; col = 0.50000000028938
This makes a list of bs:

Code: Select all

local function geta(b)
	return 1/(1-math.exp(-b))
end

local 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 b
end

for 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 = 30001
d = 0.1;  b = 6.921614307927
d = 0.2;  b = 3.2812798977898
d = 0.3;  b = 1.8010717819961
d = 0.4;  b = 0.82216324127785
d = 0.5;  b = 9.4905772130005e-09
d = 0.6;  b = -0.82216322934596
d = 0.7;  b = -1.8010717700643
d = 0.8;  b = -3.2812798929072
d = 0.9;  b = -6.9216142889459
d = 1;    b = -759.7890625

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
Hybrid Dog
Member
Posts: 2836
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

Code: Select all

-- code including much unused

local 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.png
local s = 2^10
local col = 255

local tab = {"P3", s, s, col}
local num = 5

local function info(msg)
	os.execute("notify-send '"..msg.."'")
end

local function round(n)
	return math.floor(n+0.5)
end

local function gcol(c)
	if c == math.huge
	or tostring(c) == "-nan" then
		c = 0
	end
	return round(c)%(col+1)
end

local function set(r,g,b)
	tab[num] = gcol(r)
	tab[num+1] = gcol(g)
	tab[num+2] = gcol(b)
	num = num+3
end

local sts = {}
local minc, maxc
local 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)
end


local function geta(b)
	return 1/(1-math.exp(-b))
end

local 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 b
end

local function f(x)
	return v((x+s/2)/s)*s/100--math.sqrt(math.abs(10000-x*x))
end


local crds = {}
local a,b = -s/2+1, s/2
for 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
	end
end

-- [[
for y = s/2,-s/2+1,-1 do
	for x = 1,s do
		x = x-s/2
		tset(crds[y][x])
	end
end--]]
--[[
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)
end

local function geth(x,y)
	if not hs[y] then
		return 0
	end
	return hs[y][x] or 0
end

local cx = 0
local cy = 0
local dirs = {
	{1,0},
	{0,1},
	{-1,0},
	{0,-1},
}

local dif = maxc-minc
for 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[1]
	cy = cy+ndir[2]
end

crn.x1 = crn.x1-5
crn.y1 = crn.y1-5
crn.x2 = crn.x2+5
crn.y2 = crn.y2+5

local s = {crn.x2-crn.x1, crn.y2-crn.y1}
tab[2] = s[1]+1
tab[3] = s[2]+1

maxc = 0
for y,xs in pairs(hs) do
	for _,h in pairs(xs) do
		maxc = math.max(maxc, h)
	end
end

for 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)
	end
end--]]

local dif = maxc-minc
for 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[1]
	cy = cy+ndir[2]--]]
end

info("fi")

print(table.concat(tab, " "))

local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
local msg = "fertig nach ca. "..time.."s"
if time > 0.05 then
	info(msg)
end
l think 1 y is 50 x on the picture
Image
Attachments
dsa.png
dsa.png (4.94 KiB) Viewed 913 times

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

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

Re: Post your modding questions here

by iangp » Post

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):


User avatar
Hybrid Dog
Member
Posts: 2836
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

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

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

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

Re: Post your modding questions here

by iangp » Post

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
https://en.wikipedia.org/wiki/Gradient

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):


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

Re: Post your modding questions here

by Foghrye4 » Post

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?

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your modding questions here

by paramat » Post

the 'depends.txt' file controls mod order.

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

Re: Post your modding questions here

by Foghrye4 » Post

Thank, paramat.

User avatar
Hybrid Dog
Member
Posts: 2836
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

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

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

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

Re: Post your modding questions here

by Don » Post

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

User avatar
xeranas
Member
Posts: 162
Joined: Fri Feb 05, 2016 11:06

Re: Post your modding questions here

by xeranas » Post

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?

User avatar
xeranas
Member
Posts: 162
Joined: Fri Feb 05, 2016 11:06

Re: Post your modding questions here

by xeranas » Post

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: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Post your modding questions here

by Byakuren » Post

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.

User avatar
xeranas
Member
Posts: 162
Joined: Fri Feb 05, 2016 11:06

Re: Post your modding questions here

by xeranas » Post

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

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

Re: Post your modding questions here

by garywhite » Post

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 required
2016-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
mt error.png (59.14 KiB) Viewed 913 times

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 chunk
2016-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 chunk
2016-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.lua
2016-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.lua
2016-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 required
2016-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 chunk
2016-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 chunk
2016-03-17 10:44:46: ERROR[main]: Check debug.txt for details.

User avatar
Hybrid Dog
Member
Posts: 2836
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

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

"read before asking for help"
http://wiki.minetest.net/Troubleshootin ... a.E2.80.9D

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
BrunoMine
Member
Posts: 1082
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine
Location: SP-Brasil
Contact:

Re: Post your modding questions here

by BrunoMine » Post

About the method:

Code: Select all

minetest.register_decoration()
How I can set a quantity of generated items?

User avatar
MineYoshi
Member
Posts: 5373
Joined: Wed Jul 08, 2015 13:20
Contact:

Re: Post your modding questions here

by MineYoshi » Post

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?
Have a nice day! :D

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

Re: Post your modding questions here

by iangp » Post

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 here
sound = '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: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Post your modding questions here

by Byakuren » Post

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

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Post your modding questions here

by rubenwardy » Post

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.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Hybrid Dog
Member
Posts: 2836
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

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

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

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

Re: Post your modding questions here

by iangp » Post

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):


User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Post your modding questions here

by rubenwardy » Post

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
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Locked

Who is online

Users browsing this forum: No registered users and 12 guests