Numbers within Tables not being interpreted properly

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

Numbers within Tables not being interpreted properly

by SegFault22 » Sun Aug 23, 2015 19:42

In the latest release, any attempt to interpret number values from entries in a table which is iterated through by ipairs() (using each row in the table for the next property to be passed on to the registering code) fails on account of "attempt to index local 'row' (a number value)". Considering the fact that minetest.register_ore requires number values (and cannot properly make use of string values) for the parameters clust_scarcity, clust_num_ores, clust_size, y_min, and y_max (and noise_threshold in the case of sheet-type ores), all mods which iterate through a table of entries with those parameters and register ores with those parameters are now broken and cannot function properly at the step where the number values are read from the table. Here's an example of some code that was working before this change, but is now defunct:
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
ORES = {
{ "ores:ore_antimony", "default:stone", 16*16*16, 6, 2, -24576, -4096 },
{ "ores:ore_manganese", "default:stone", 17*17*17, 6, 2, -16384, -8192 },
{ "ores:ore_molybdenum", "default:stone", 18*18*18, 6, 2, -16384, -4096 },
}

for _, row in ipairs(ORES) do
   local ore_id = row[1]
   local ore_wherein = row[2]
   local ore_clust_scarcity = row[3]
   local ore_clust_num_ores = row[4]
   local ore_clust_size = row[5]
   local ore_hmin = row[6]
   local ore_hmax = row[7]
   
   minetest.register_ore({
      ore_type       = "scatter",
      ore            = ore_id,
      wherein        = ore_wherein,
      clust_scarcity = ore_clust_scarcity,
      clust_num_ores = ore_clust_num_ores,
      clust_size     = ore_clust_size,
      height_min     = ore_hmin,
      height_max     = ore_hmax,
   })
end

Before the recent updates, it was possible to use such code without problems, but now all of a sudden this error is thrown, because someone changed something very important within the core (which should never be modified by anyone who doesn't know what they are doing with the pretty lines of code on their screen or has not used minetest long enough to understand what they are doing when they change critically important parts of the engine). Until this is fixed, you now have to convert all entries within those tables to string values, and use tonumber() at the minetest.register_ore() call in order to convert those string values back into number values.

Is anyone else experiencing this kind of problem? Or have mods simply not yet advanced far enough to iterate through a table of entries (instead of repeating minetest.register_ore() and the other registry function calls for every single registry entry, which appears to be used profusely)
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Numbers within Tables not being interpreted properly

by rubenwardy » Tue Aug 25, 2015 06:58

I don't understand how such a regression is possible - ipairs would be in core Lua.

Are you using Lua or luajit?
 

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

Re: Numbers within Tables not being interpreted properly

by SegFault22 » Tue Aug 25, 2015 08:26

Whichever comes standard with Minetest 0.4.13 is the one I am using. It might just be a simple problem with my tables being formatted improperly (or a similar error), which has happened several times when importing old code from the earlier manifestation of the mod I am working on. I now doubt that it is a problem with the engine itself - If this error ends up being thrown when I try running the old (previously working) code, then there really is a serious problem. I will reply again after I have tested it, which will be later because some other stuff has to be done between now and then.
Last edited by SegFault22 on Tue Aug 25, 2015 08:53, edited 1 time in total.
 

User avatar
ArguablySane
Member
 
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Numbers within Tables not being interpreted properly

by ArguablySane » Tue Aug 25, 2015 08:51

I just tested this on Minetest 0.4.13-dev using the following code:
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 nums = {{1,2,3},{4,5,6},{7,8,9}}
   for _, row in ipairs(nums) do
      minetest.chat_send_all(row[1]+row[2]+row[3])
   end

It seems to work exactly as expected.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

Re: Numbers within Tables not being interpreted properly

by SegFault22 » Tue Aug 25, 2015 08:54

ArguablySane wrote:I just tested this on Minetest 0.4.13-dev using the following code:
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 nums = {{1,2,3},{4,5,6},{7,8,9}}
   for _, row in ipairs(nums) do
      minetest.chat_send_all(row[1]+row[2]+row[3])
   end

It seems to work exactly as expected.

Then it is a problem with my mod code. Probably a missing bracket or something like that.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Numbers within Tables not being interpreted properly

by rubenwardy » Tue Aug 25, 2015 16:26

Are you using the official Windows Minetest 0.4.13 build then, MSVC++?
 

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

Re: Numbers within Tables not being interpreted properly

by SegFault22 » Tue Aug 25, 2015 21:20

I do not use Windows. My OS is Linux Mint, and I installed the latest Minetest from the PPA through the Update Manager.
 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 16 guests

cron