local function get_node_group(name, group)
if not minetest.registered_nodes[name] or not minetest.registered_nodes[name].groups[group] then
return 0
end
return minetest.registered_nodes[name].groups[group]
end
celeron55 wrote:You need to check:
1) if the node is registered (otherwise you will fail miserably if the node is unknown)
2) if the node has the group set
3) if the node has the group set to something else than 0 (because 0 is still "not set")
Something like:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local function get_node_group(name, group)
if not minetest.registered_nodes[name] or not minetest.registered_nodes[name].groups[group] then
return 0
end
return minetest.registered_nodes[name].groups[group]
end
If it returns 0, the node is not in the group (same as rating=0); otherwise the returned value is the rating of the group.
Also one should remember that in Lua the only values that are false are false and nil. 0 is true. 8)
I'll include something like this in the API in the future.
Fun fact: the leaf decay code fails to check if a node is registered and causes crashes for people with unknown nodes. Fixed already in github though.
Users browsing this forum: No registered users and 9 guests