How to refer to args in abm definition?

Post Reply
User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

How to refer to args in abm definition?

by azekill_DIABLO » Post

I have defined an abm, here it is.

Code: Select all

minetest.register_abm({ 
			nodenames = params.nodenames or {"default:dirt_with_grass"},
			neighbors = params.neighbors or {"air"},
			interval = params.interval or 300,
			chance = params.chance or 1000, 
			min_light = params.min_light or 0,
			max_light = params.max_light or 7,
			action = <do fun things!>
		})
But I have no clue on how to refer to min_light and max_light in 'action' where I need to use them. Do i have to use something like def.min_light?
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
Andrey01
Member
Posts: 2577
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: How to refer to args in abm definition?

by Andrey01 » Post

azekill_DIABLO wrote:I have defined an abm, here it is.

Code: Select all

minetest.register_abm({ 
			nodenames = params.nodenames or {"default:dirt_with_grass"},
			neighbors = params.neighbors or {"air"},
			interval = params.interval or 300,
			chance = params.chance or 1000, 
			min_light = params.min_light or 0,
			max_light = params.max_light or 7,
			action = <do fun things!>
		})
But I have no clue on how to refer to min_light and max_light in 'action' where I need to use them. Do i have to use something like def.min_light?
As these parameters belong to "abm_definition_table" try to refer so (I don`t sure exactly it will work):

Code: Select all

abm_definition_table[min_light] or abm_definition_table[max_light]

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: How to refer to args in abm definition?

by azekill_DIABLO » Post

Thanks for this answer. I will see if it works!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: How to refer to args in abm definition?

by Krock » Post

I wonder what kind of API documentation file you two are reading because light conditions in the ABM definition do not exist.
Here's the definition of all table keys which can be assigned: https://github.com/minetest/minetest/bl ... 5097-L5127
This means you'll have to implement the light checks yourself - in the `action` function. Here's how it could look like: (untested)

Code: Select all

action = function(pos, node)
	local light = minetest.get_node_light(pos)
	if not light or light < (params.min_light or 0) or light > (params.max_light or 7) then
		return
	end
	-- Do something here
end

See also: what MTG's flowers mod does
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: How to refer to args in abm definition?

by azekill_DIABLO » Post

It's just absolutly what I did first Krock. params.min/max_light doesn't work for the third line (of your code). The debbuger says it can't be concatenated.
However this code placed in 'action' works:

Code: Select all

print("min_light = " .. params.min_light .. " and max_light = " .. params.max_light)
It returns:
min_light = 0 and max_light = 7
It's weird because my code (in 'action' part) looks like this:

Code: Select all

action = function(pos, node)
   local node_light = minetest.get_node_light(pos)
   print("wanna spawn something with light : " .. node_light)                                       -- Works
   print("min_light = " .. params.min_light .. " and max_light = " .. params.max_light)             -- Works
   if node_light >= params.min_light and node_light <= params.max_light then                        -- Doesn't work :'(
      print('light checks ok')
      <action>
   end
end
The if part bugs, but the print part does.
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
Andrey01
Member
Posts: 2577
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: How to refer to args in abm definition?

by Andrey01 » Post

Krock wrote:I wonder what kind of API documentation file you two are reading because light conditions in the ABM definition do not exist.
Here's the definition of all table keys which can be assigned: https://github.com/minetest/minetest/bl ... 5097-L5127
This means you'll have to implement the light checks yourself - in the `action` function. Here's how it could look like: (untested)

Code: Select all

action = function(pos, node)
	local light = minetest.get_node_light(pos)
	if not light or light < (params.min_light or 0) or light > (params.max_light or 7) then
		return
	end
	-- Do something here
end

See also: what MTG's flowers mod does
Ah, i did not know. I am reading dev.minetest.net and this manual is really messy to me because there are all explainations are too short and that`s why i need to ask to Minetest Community to explain me something. Minetest GitHub repo is messy, too as i need to rummage long to find out something.

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: How to refer to args in abm definition?

by azekill_DIABLO » Post

Bump: I didn't find any work around nor reference on how to use that. I could probably find another way to do that but it would be laggy.
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests