~ Forums of Enroth ~
Would you like to react to this message? Create an account in a few clicks or log in to continue.

~ Forums of Enroth ~

An Enroth diehard fan community
 
HomeHome  SearchSearch  RegisterRegister  Log inLog in  
Latest topics
» Immortal Realms: Vampire Wars (HoMM like game)
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Unknown_Hero 2020-09-18, 23:10

» They talked about fheroes2!
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby sirDranik 2020-09-13, 02:51

» GoG Homm2 vs fheroes2 comparison review
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby sirDranik 2020-09-11, 01:19

» Resurrection of fheroes2 with 0.8 version
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Tibor0803 2020-09-08, 06:32

» [Enhancement] Enhancement for the information displayed when the player right clicks on an object
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby sirDranik 2020-09-07, 20:45

» Free Heroes of Might and Magic II (fheroes2) General Announcements
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby ihhub 2020-09-05, 02:34

» [Enhancement] Enhancement for Scouting secondary skill
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Unknown_Hero 2020-09-03, 21:26

Poll
Global announcements should be:
Everlasting, 1 for each project.
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar110%[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar12
 0% [ 0 ]
Temporary, when there is something new to announce.
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar11100%[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar12
 100% [ 6 ]
Holalala... No idea where the Ultimate artifact is.
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar110%[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Redbar12
 0% [ 0 ]
Total Votes : 6
Most Viewed Topics
H3SW: General Graphics discussion
Ragoon's Graphics For HoMM3SW
H3SW General Discussion
H3SW Map List: Work in progress
H3SW: Dwelling Development
Heroes III: The Succession Wars v0.8.1 Beta
Heroes of Might and Magic 3: The Succession Wars - General info & Announcements
Project Ironfist announcements
Introduce yourself
Welcome fellow Enrothians!

 

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

Go down 
AuthorMessage
Unknown_Hero
Mage
Mage
Unknown_Hero

Messages : 724
Quality Points : 74
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 : 280
Quality Points : 45
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 : 280
Quality Points : 45
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 : 280
Quality Points : 45
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
Mage
Mage
Unknown_Hero

Messages : 724
Quality Points : 74
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 : 280
Quality Points : 45
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
Mage
Mage
Unknown_Hero

Messages : 724
Quality Points : 74
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: