~ 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 ~

The Enroth diehard fan community
 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  
Latest topics
» Songs of Silence (HoMM like game)
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Blake01 2024-03-27, 16:52

» Heroes Orchestra's 5th Birthday concerts with Paul Romero
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby rrravyn 2024-03-23, 22:45

» WARNING - The dreaded moment is here: Heroes 6 servers shutting down
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Sir Albe 2024-03-22, 07:15

» fheroes2 General Announcements
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby sirDranik 2024-03-17, 23:35

» Photo Gallery
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby Sir Albe 2024-03-07, 06:57

» Polskie powitanie
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby rrravyn 2024-03-05, 04:02

» Heroes II localisation: how to make no-CD patch.
[Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file Icon_minitimeby kiku 2024-02-19, 02:43

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
Introduce yourself
H3SW General Discussion
H3SW Map List: Work in progress
H3SW: Dwelling Development
Forum Admins Feed
The Floody Land
Enrothian Fan Art
Heroes III: The Succession Wars v0.8.1 Beta

 

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

Go down 
2 posters
AuthorMessage
Unknown_Hero
Mage
Mage
Unknown_Hero


Messages : 778
Quality Points : 78
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 : 288
Quality Points : 47
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 : 288
Quality Points : 47
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 : 288
Quality Points : 47
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 : 778
Quality Points : 78
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 : 288
Quality Points : 47
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 : 778
Quality Points : 78
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
 Similar topics
-
» [Ironfist ver 1.3.0+] Fatal error when loading an old save file
» [Ironfist ver 1.3.0+] The bass.dll file is missing after installation
» [Ironfist ver 1.3.0] Bug field for save file name full of dots and crash
» [Ironfist ver 1.3.0] Bug troops in garrison not saved in save file with crash
» [Ironfist ver 1.3.0] Debug error message with an original Heroes 2 save file

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: