Check node group

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Check node group

by neko259 » Sun Apr 08, 2012 09:49

How do I check if some node is in a specific group? I can't find such example in the API reference.
Bitcoin donations: 18r66dJmUjwTmWRTFnorpGMzs8d4B8jzbw
 

celeron55
Member
 
Posts: 430
Joined: Tue Apr 19, 2011 10:10

by celeron55 » Sun Apr 08, 2012 13:18

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.
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

by neko259 » Sun Apr 08, 2012 13:41

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.

Thank you. I'll try to use that to check nodes flammability.
Bitcoin donations: 18r66dJmUjwTmWRTFnorpGMzs8d4B8jzbw
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

by neko259 » Sun Apr 08, 2012 13:54

Or maybe I won't. I see you already add fire to minetest_game, so my mod is useless now :)
Bitcoin donations: 18r66dJmUjwTmWRTFnorpGMzs8d4B8jzbw
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 6 guests

cron