Use group help

Post Reply
User avatar
ulla
Member
Posts: 143
Joined: Wed Feb 04, 2015 09:22
GitHub: IIIullaIII
IRC: ulla
In-game: ulla

Use group help

by ulla » Post

Hi how i use group in this case is possible
function minetest.grow_canapa_red(pos, node)
pos.y = pos.y - 1
local name = minetest.get_node(pos).name
if name ~= "default:desert_sand" and name ~= "default:sand" then
return
end.......................

I would like to use all types of sand ,for example
default sand ,
desert_sand ,
silver sand ....
I know group_sand exists ,but how do you use for example in this code ?
group_dirt exists?
example
dirt ,
dirt_with_grass ,
dry_dirt_with_drygras .... ?
is right?
function minetest.grow_canapa_red(pos, node)
pos.y = pos.y - 1
local name = minetest.get_node(pos).name
if name ~= "default:group_sand" and name ~= "default:group_dirt" then
return
end.......................


or i need use table?

Code: Select all

local groups_sand={
{"desert_sand"},
{"sand"},
{"silver_sand"}
}
for i in ipairs(groups_sand) do
	local g_sand = group_sand[i][1]

function minetest.grow_canapa_red(pos, node)
	pos.y = pos.y - 1
	local name = minetest.get_node(pos).name
	if name ~= "default:"..g_sand then
		return
	end..............
X4cna2d4UqsiawIzUumDgPoYNx3JLGII

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

Re: Use group help

by Andrey01 » Post

There`s a group named "sand" for all types of sand. In your case you need to apply minetest.get_item_group(name, group) function (also there`s an alternative one minetest.get_node_group(name, group), but it`s deprecated):

Code: Select all

function group_canapa_red(pos, node)
      pos.y = pos.y - 1
      local name = minetest.get_node(pos).name
      if not minetest.get_item_group(name, "sand") then
            return
      end
end
For dirts there`s a "soil" group. Also, I`d not advice to use "minetest" global table as it`s assigned for the internal usage in the engine.

User avatar
ulla
Member
Posts: 143
Joined: Wed Feb 04, 2015 09:22
GitHub: IIIullaIII
IRC: ulla
In-game: ulla

Re: Use group help

by ulla » Post

Hello Thanks for the answer
I solved it this way

Code: Select all

function minetest.grow_canapa(pos, node)
	pos.y = pos.y - 1
	local name = minetest.get_node(pos).name
	if             name ~= "default:dirt_with_grass" 
	           and name ~= "default:dirt" 
	           and name ~= "default:dirt_with_rainforest_litter"
	           and name ~= "default:dry_dirt"
	           and name ~= "default:dirt_with_snow"
	           and name ~= "default:dirt_with_conifereous_litter"   
	            then
		return
	end
	if not minetest.find_node_near(pos, 1, {"group:water"}) then
		return
	end...............................
	
but I wanted to avoid and and and and and :-P
ps I tryed with table too but for the function can't work because only the last one in the list is used
X4cna2d4UqsiawIzUumDgPoYNx3JLGII

User avatar
Pyrollo
Developer
Posts: 385
Joined: Mon Jan 08, 2018 15:14
GitHub: pyrollo
In-game: Naj
Location: Paris

Re: Use group help

by Pyrollo » Post

Hi,

You can not test item group with your code :

Code: Select all

local name = minetest.get_node(pos).name
if name ~= "default:group_sand"
In that code name holds the item string, i.e. "default:sand", it will never be equal to "default:group_sand" (which corresponds to nothing btw).

Instead, test group this way :

Code: Select all

local name = minetest.get_node(pos).name
if minetest.get_item_group(name, "sand") == 0
get_item_group returning 0 means item not in group.
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 11 guests