~ Forums of Enroth ~

An Enroth diehard fan community
 
HomeHome  FAQFAQ  SearchSearch  RegisterRegister  Log inLog in  
Latest topics
» [H3SW v0.8.1] Crash when I wear the Crystal Ball and right-click neutral packs (also Visions Spell)
by Orzie Yesterday at 02:11

» [H3SW V0.8.1] HD mod keeps changing resolution
by Orzie 2019-02-16, 18:47

» Heroes III: The Succession Wars v0.8.1 Beta
by qlczas_PL 2019-02-15, 19:05

» [H3SW V0.8.1] Enemy AI turn stuck (Using Teleporters infinitely)
by wielkaberta 2019-02-12, 03:50

» Campaign in future?
by DeusEx 2019-02-11, 21:10

» Hiro's hero biographies for H3SW
by Orzie 2019-02-11, 06:00

» [H3SW v0.8.1] Map - Beltway
by Orzie 2019-02-11, 04:00

Poll
"Wait" in HoMM2?
Yes
80%
 80% [ 55 ]
No
20%
 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 : 459
Quality Points : 58
Registration Date : 2015-09-06

PostSubject: [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"? Question
Back to top Go down
Darmani
Master Modder
Master Modder
Darmani

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

PostSubject: Re: [Ironfist ver 1.3.0] Bug with tables in lua script when loading a save file   2019-01-01, 11:43

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

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

PostSubject: 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>
Back to top Go down
Darmani
Master Modder
Master Modder
Darmani

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

PostSubject: 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.
Back to top Go down
Unknown_Hero
Vampire
Vampire
Unknown_Hero

Messages : 459
Quality Points : 58
Registration Date : 2015-09-06

PostSubject: 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. 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 : 237
Quality Points : 38
Registration Date : 2014-12-27

PostSubject: 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.
Back to top Go down
Unknown_Hero
Vampire
Vampire
Unknown_Hero

Messages : 459
Quality Points : 58
Registration Date : 2015-09-06

PostSubject: 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. Smile
Back to top Go down
Sponsored content




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

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
-
» HTML and Tables
» How do I get the bodyline background to be transparent but the subforum tables to be normal?
» Tables help in the character sheets
» How to remove default padding in bbcode tables (in Invision version)?
» Ammo Crate End Tables

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: