I have noticed that group definitions are within a table, and the group "name" is an index in the table, and the number "level" for that group is stored "at" the index. The index is not a string in any examples I have found. And, when I try to test whether strings are acceptable as the index, an error is thrown: "'}' expected near '='". So, it is not currently possible for groups table indexes to be strings.
I have not found any way to insert group definitions into a table, said table being the groups table passed to the minetest.register_craftitem() function call. The only way I have found to "insert" group definitions is for them to be written out directly into a table, like this:
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
groups = {metal = 1, ingot = 1, silver = 1}
...
groups = groups,
...
It is essential to my mod that the group definitions be stored in a table within a table at a certain index, because they are retrieved from separate tables full of data, such as a table of "item types" which defines "ingot", a table of "materials" which defines "silver", and a table of "material types" which defines "metal". When we need to put the group definitions to the groups table, the information has to be fetched from some index in a sub-table (like the numerical index 4), which is located at some other known index in the data table (such as "ingot"). Is there any way to have each group definition stored at some variable, then put the values from those variables together into the groups table? It should be such that if I had these variables (or similar):
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
a = {metal = 1}
b = {ingot = 1}
c = {silver = 1}
the resulting groups table would be this:
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
groups = {metal = 1, ingot = 1, silver = 1}
Better yet, is there a way to convert strings like "ingot", "metal", etc. to the undeclared variables for the group names, and then put them into the groups table?
I have tried everything that I know of, such as table index tricks and table.concat() (which returns a useless string, remember we get that error if the group name is a string and not an unassigned variable)...
Is this even possible? If so, how?
If this is possible, I suggest that information regarding how to do this should be added to the developer wiki page at http://dev.minetest.net/Groups, because that is where I first went to try and find out how to do this, before searching the Lua documentation to no avail.