Difference between revisions of "minetest.raillike group"

From Minetest Developer Wiki
Jump to navigation Jump to search
m (Add DISPLAYTITLE.)
(Add info for this function)
Line 1: Line 1:
 
{{DISPLAYTITLE:minetest.raillike_group}}
 
{{DISPLAYTITLE:minetest.raillike_group}}
 +
Creates or retrieves a rating value based on a name, for use with the <code>connect_to_raillike</code> group in [[minetest.register_node]].
 +
 +
== Syntax ==
 +
<source>minetest.raillike_group("name")</source>
 +
 +
== Description ==
 +
When defining a node, the <code>connect_to_raillike</code> group requires a numeric rating value, so that nodes with the same rating can visually connect together (like rails do when placing them next to each other). This function registers (if it does not exist) or retrieves (if it already exists) a rating value based on a name, and returns it. That name that can be shared by multiple mods, so that all mods that use the same name will be assigned the same rating value.
 +
 +
== Example ==
 +
This code will create a node "my_mod:my_gunpowder" that will be able to visually connect to any nodes that used the name "gunpowder" to invoke this function, like the TNT mod in the Minetest game, but won't be able to visually connect to any nodes that used a different name, even if adjacent:
 +
 +
<source>
 +
minetest.register_node("my_mod:my_gunpowder", {
 +
    ...
 +
    drawtype = "raillike",
 +
    ...
 +
    groups = { connect_to_raillike = minetest.raillike_group("gunpowder"),
 +
              ... }
 +
})
 +
</source>
 +
 
[[Category:Methods]]
 
[[Category:Methods]]
{{Incomplete}}
 

Revision as of 22:04, 16 November 2018

Creates or retrieves a rating value based on a name, for use with the connect_to_raillike group in minetest.register_node.

Syntax

minetest.raillike_group("name")

Description

When defining a node, the connect_to_raillike group requires a numeric rating value, so that nodes with the same rating can visually connect together (like rails do when placing them next to each other). This function registers (if it does not exist) or retrieves (if it already exists) a rating value based on a name, and returns it. That name that can be shared by multiple mods, so that all mods that use the same name will be assigned the same rating value.

Example

This code will create a node "my_mod:my_gunpowder" that will be able to visually connect to any nodes that used the name "gunpowder" to invoke this function, like the TNT mod in the Minetest game, but won't be able to visually connect to any nodes that used a different name, even if adjacent:

minetest.register_node("my_mod:my_gunpowder", {
    ...
    drawtype = "raillike",
    ...
    groups = { connect_to_raillike = minetest.raillike_group("gunpowder"),
               ... }
})