~ Forums of Enroth ~

An Enroth diehard fan community
 
HomeHome  FAQFAQ  SearchSearch  RegisterRegister  Log inLog in  
Latest topics
» Project Ironfist announcements
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Unknown_Hero Today at 09:55

» Czech language
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Kattnienika Yesterday at 19:16

» Introduce yourself
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby GodRage 2019-05-24, 01:22

» [Unknown Mod] General Informations
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Unknown_Hero 2019-05-23, 06:17

» [Heroes 2 Bugs] Crash or/and View Puzzle map corrupted when visiting an obelisk
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Unknown_Hero 2019-05-18, 02:46

» Enroth's History & Stories
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Orzie 2019-05-13, 17:39

» [H3SW v0.8.1] Necromancer castles cause my game to crash (Sometimes)
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Orzie 2019-05-13, 17:22

Poll
"Wait" in HoMM2?
Yes
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar1180%[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar12
 80% [ 55 ]
No
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar1120%[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar12
 20% [ 14 ]
Total Votes : 69
Most Viewed Topics
H3SW: General Graphics discussion
Ragoon's Graphics For HoMM3SW
H3SW General Discussion
H3SW: Dwelling Development
Heroes of Might and Magic 3: The Succession Wars - General info & Announcements
H3SW Map List: Work in progress
Welcome fellow Enrothians!
Enrothian Fan Art
Commanders?
H3SW Recruitment Point - Enroth Needs You!

Share
 

 [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file

Go down 
AuthorMessage
Unknown_Hero
Vampire
Vampire
Unknown_Hero

Messages : 465
Quality Points : 60
Registration Date : 2015-09-06

[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Empty
PostSubject: [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 Icon_minitime2018-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"? Question
Back to top Go down
Darmani
Master Modder
Master Modder
Darmani

Messages : 238
Quality Points : 38
Registration Date : 2014-12-27

[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Empty
PostSubject: 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 Icon_minitime2019-01-01, 11:43

Noted.
Back to top Go down
Darmani
Master Modder
Master Modder
Darmani

Messages : 238
Quality Points : 38
Registration Date : 2014-12-27

[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Empty
PostSubject: 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 Icon_minitime2019-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>
Back to top Go down
Darmani
Master Modder
Master Modder
Darmani

Messages : 238
Quality Points : 38
Registration Date : 2014-12-27

[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Empty
PostSubject: 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 Icon_minitime2019-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.
Back to top Go down
Unknown_Hero
Vampire
Vampire
Unknown_Hero

Messages : 465
Quality Points : 60
Registration Date : 2015-09-06

[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Empty
PostSubject: 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 Icon_minitime2019-01-07, 07:19

It's good that you found a quick fix for the numbers. Smile
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. Smile
Back to top Go down
Darmani
Master Modder
Master Modder
Darmani

Messages : 238
Quality Points : 38
Registration Date : 2014-12-27

[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Empty
PostSubject: 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 Icon_minitime2019-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.
Back to top Go down
Unknown_Hero
Vampire
Vampire
Unknown_Hero

Messages : 465
Quality Points : 60
Registration Date : 2015-09-06

[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Empty
PostSubject: 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 Icon_minitime2019-01-07, 11:44

Ah, I see, the value of "key" in the tag "tableElement" in the save file, thank you I understand better. Smile
Back to top Go down
Sponsored content




[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Empty
PostSubject: 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 Icon_minitime

Back to top Go down
 
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
~ Forums of Enroth ~ :: Modding Guild :: Heroes of Might and Magic II: Project Ironfist :: Bug Reports-
Jump to: