[Gearbox] Lua tables not preserved between scopes

A problem that I’ve run into is that lua tables are not preserved/passed between ship scopes (Scripts referenced by addCustomCode) and the gamerule scope. (leveldata/multiplayer/gamemode.lua)

Consider the following example:

data:scripts/testtable.lua

TestTable =
{
    SomeParameter = nil;
};

data:ship/hgn_carrier/hgn_carrier.lua

dofilepath("data:scripts/testtable.lua");

function Create_Hgn_Carrier(CustomGroup, playerIndex, shipID)
    TestTable.SomeParameter = 654951359;
end

function Update_Hgn_Carrier(CustomGroup, playerIndex, shipID)
    print("[Hgn_Carrier] SomeParameter is: "..tostring(TestTable.SomeParameter));
end

data:leveldata/multiplayer/gamerule.lua

...
dofilepath("data:scripts/testtable.lua");
function OnInit()
    ... -- Init code here
    Rule_AddInterval("CheckParameter", 1.0);
end

function CheckParameter()
    print("[GameRule] SomeParameter is: "..tostring(TestTable.SomeParameter));
end

Which results in the following output in HwRM.log:

 [GameRule] SomeParameter is: nil
 [Hgn_Carrier] SomeParameter is: 654951359

This prevents lua tables from being used to pass data between ships and the gamerule.

Gearbox would you please implement a fix for this or provide some form of a formal facility for passing data between the two scopes?

1 Like

To get around this limitation I think you will have to write the data to a file and then read the file when you want to access the data again. Here’s a very basic example:

http://forums.relicnews.com/showthread.php?29676-File-I-O-works-fine