Poll | | Global announcements should be: | Everlasting, 1 for each project. | | 0% | [ 0 ] | Temporary, when there is something new to announce. | | 100% | [ 6 ] | Holalala... No idea where the Ultimate artifact is. | | 0% | [ 0 ] |
| Total Votes : 6 |
|
| | [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file | |
| | Author | Message |
---|
Unknown_Hero Mage
Messages : 778 Quality Points : 78 Registration Date : 2015-09-06
| Subject: [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file 2018-12-01, 08:51 | |
| Bug with tables in lua script when loading a save file. Launch ironfist.exe 1.3.0 Load _MapTest.MX2.lua with any scenario (rename the scenario or the script). The message box displays: Variable: 0 Table: 0 End the turn twice. The message box displays: Variable: 2 Table: 2 Save the game. Load the save you just saved. End the turn. Then bug. The message box displays: Variable: 3.0 Table: 0 The message box should display: Variable: 3 Table: 3 The lua script contains only this code: - Code:
-
testVariable = 0; testTable = {};
mapVariables = {"testVariable", "testTable"};
function OnNewDay(month, week, day) MessageBox("Variable: "..testVariable.."\nTable: "..#testTable..""); testVariable = testVariable + 1; table.insert(testTable, 1); end And also why "Variable: 3.0" instead of "Variable: 3"? | |
| | | Darmani Master Modder
Messages : 288 Quality Points : 47 Registration Date : 2014-12-27
| Subject: Re: [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file 2019-01-01, 11:43 | |
| | |
| | | Darmani Master Modder
Messages : 288 Quality Points : 47 Registration Date : 2014-12-27
| Subject: Re: [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file 2019-01-06, 17:50 | |
| Preliminary investigation: It looks the data is actually present and being saved correctly. However, something about the save process is converting integers into floating point numbers. Depending on how Lua works, this will either be easy or very hard to fix. I'm going to take 15 minutes to work on this; if I can't do it in that time, I'll downgrade this until it's actually known to cause an issue. Here's what I'm seeing in a savegame file: - Code:
-
<mapVariable id="testTable" type="table"> <table xmlns="" tableId="testTable"> <tableElement xmlns="" key="1.000000" type="number" value="1.000000"/> <tableElement xmlns="" key="2.000000" type="number" value="1.000000"/> <tableElement xmlns="" key="3.000000" type="number" value="1.000000"/> <tableElement xmlns="" key="4.000000" type="number" value="1.000000"/> </table> </mapVariable>
| |
| | | Darmani Master Modder
Messages : 288 Quality Points : 47 Registration Date : 2014-12-27
| Subject: Re: [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file 2019-01-06, 19:41 | |
| There are two issues here:
1) Due to a quirk in Lua, all numbers were being converted to floats upon save/reload. This is now fixed. 2) It looks like tables were originally built to assume all keys are strings. Any other keys will be converted to strings upon save/reload. This unfortunately made it through code review. I have put this in our task list, and updated the documentation to warn of this. | |
| | | Unknown_Hero Mage
Messages : 778 Quality Points : 78 Registration Date : 2015-09-06
| Subject: Re: [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file 2019-01-07, 07:19 | |
| It's good that you found a quick fix for the numbers. I did some additional tests. With the value 1 replaced by the value "Hello" in the table... - Code:
-
testVariable = 0; testTable = {};
mapVariables = {"testVariable", "testTable"};
function OnNewDay(month, week, day) MessageBox("Variable: "..testVariable.."\nTable: "..#testTable..""); testVariable = testVariable + 1; table.insert(testTable, "Hello"); end ...savegame file: - Code:
-
<mapVariable id="testTable" type="table"> <table xmlns="" tableId="testTable"> <tableElement xmlns="" key="1.000000" type="string" value="Hello"/> <tableElement xmlns="" key="2.000000" type="string" value="Hello"/> <tableElement xmlns="" key="3.000000" type="string" value="Hello"/> </table> </mapVariable>
<mapVariable id="testVariable" type="number" value="3.000000"/> With the value 1 replaced by the value false in the table... - Code:
-
testVariable = 0; testTable = {};
mapVariables = {"testVariable", "testTable"};
function OnNewDay(month, week, day) MessageBox("Variable: "..testVariable.."\nTable: "..#testTable..""); testVariable = testVariable + 1; table.insert(testTable, false); end ...savegame file: - Code:
-
<mapVariable id="testTable" type="table"> <table xmlns="" tableId="testTable"> <tableElement xmlns="" key="1.000000" type="boolean" value="0"/> <tableElement xmlns="" key="2.000000" type="boolean" value="0"/> <tableElement xmlns="" key="3.000000" type="boolean" value="0"/> </table> </mapVariable>
<mapVariable id="testVariable" type="number" value="3.000000"/> With the value 1 replaced by the value "Hello" in the table and function OnMapStart()... - Code:
-
function OnMapStart() testVariable = 0; testTable = {}; MessageBox("OnMapStart."); end
mapVariables = {"testVariable", "testTable"};
function OnNewDay(month, week, day) MessageBox("Variable: "..testVariable.."\nTable: "..#testTable..""); testVariable = testVariable + 1; table.insert(testTable, "Hello"); end ...savegame file: - Code:
-
<mapVariable id="testTable" type="table"> <table xmlns="" tableId="testTable"> <tableElement xmlns="" key="1.000000" type="string" value="Hello"/> <tableElement xmlns="" key="2.000000" type="string" value="Hello"/> <tableElement xmlns="" key="3.000000" type="string" value="Hello"/> </table> </mapVariable>
<mapVariable id="testVariable" type="number" value="3.000000"/> And I got the same result for all cases... The message box displays: Variable: 3.0 Table: 0 ...for all value types, the tables are ignored when loading a save file. If it helps. | |
| | | Darmani Master Modder
Messages : 288 Quality Points : 47 Registration Date : 2014-12-27
| Subject: Re: [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file 2019-01-07, 11:27 | |
| Hi,
I said key types must be strings, not value types. Value types can be anything, including other tables. When you call table.insert on an empty table, it uses 1 as the key, which is not a string. | |
| | | Unknown_Hero Mage
Messages : 778 Quality Points : 78 Registration Date : 2015-09-06
| Subject: Re: [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file 2019-01-07, 11:44 | |
| Ah, I see, the value of "key" in the tag "tableElement" in the save file, thank you I understand better. | |
| | | Sponsored content
| Subject: Re: [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file | |
| |
| | | | [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file | |
|
Similar topics | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| |