Context is i'm making a mod for Star Ruler, which uses AngelScript as scripting language. The engine exposes a function "getSubSystemDefByName()" that returns a "const subSystemDef@".
Now here's my code:
const subSystemDef@ ssdCity, ssdMetal, ssdElec, ssdAdvpt, ssdPort, ssdFarm,
ssdGoods, ssdLux, ssdYard, ssdResearch, ssdBunker, ssdCannon,
ssdLaser, ssdShield, ssdFuel, ssdAmmo, ssdCargo, ssdEngine, ssdCapital, ssdGCapital;
bool subSystemDefInitialized = false;
// const subSystemDef@ [] allSsd(19, null);
void initSSD() {
if (!subSystemDefInitialized) {
@ssdCity = getSubSystemDefByName("City");
@ssdMetal = getSubSystemDefByName("MetalMine");
@ssdElec = getSubSystemDefByName("ElectronicFact");
@ssdAdvpt = getSubSystemDefByName("AdvPartFact");
@ssdFarm = getSubSystemDefByName("Farm");
@ssdPort = getSubSystemDefByName("SpacePort");
@ssdGoods = getSubSystemDefByName("GoodsFactory");
@ssdLux = getSubSystemDefByName("LuxsFactory");
@ssdYard = getSubSystemDefByName("ShipYard");
@ssdResearch = getSubSystemDefByName("SciLab");
@ssdBunker = getSubSystemDefByName("Bunker");
@ssdCannon = getSubSystemDefByName("PlanetCannon");
@ssdLaser = getSubSystemDefByName("PlanetLaser");
@ssdShield = getSubSystemDefByName("PlanetShields");
@ssdFuel = getSubSystemDefByName("FuelDepot");
@ssdAmmo = getSubSystemDefByName("AmmoDepot");
@ssdCargo = getSubSystemDefByName("CargoBlock");
@ssdEngine = getSubSystemDefByName("PlanetEngine");
@ssdCapital = getSubSystemDefByName("Capital");
@ssdGCapital = getSubSystemDefByName("GalacticCapital");
[color=#0000cd]const
[color=#FF0000]subSystemDef@[] allSsd = {
@ssdCity, @ssdMetal, @ssdElec, @ssdAdvpt,
@ssdFarm, @ssdPort, @ssdGoods, @ssdLux,
@ssdYard, @ssdResearch, @ssdBunker, @ssdCannon,
@ssdLaser, @ssdShield, @ssdFuel, @ssdAmmo,
@ssdCargo, @ssdEngine, @ssdCapital
};
}
subSystemDefInitialized = true;
}
Problem is, the red lines give compiler errors:
AS Server Error in M:\My Games\Star Ruler\Mods\MyMod\Game Data\scripts\server\planet.as: Compiling void initSSD()
line: 688, col: 1
AS Server Error in M:\My Games\Star Ruler\Mods\MyMod\Game Data\scripts\server\planet.as: Can't implicitly convert from 'const subSystemDef@' to 'subSystemDef@'.
line: 712, col: 4
AS Server Error in M:\My Games\Star Ruler\Mods\MyMod\Game Data\scripts\server\planet.as: Can't implicitly convert from 'const subSystemDef@' to 'subSystemDef@'.
line: 712, col: 14
AS Server Error in M:\My Games\Star Ruler\Mods\MyMod\Game Data\scripts\server\planet.as: Can't implicitly convert from 'const subSystemDef@' to 'subSystemDef@'.
line: 712, col: 25
AS Server Error in M:\My Games\Star Ruler\Mods\MyMod\Game Data\scripts\server\planet.as: Can't implicitly convert from 'const subSystemDef@' to 'subSystemDef@'.
line: 712, col: 35
AS Server Error in M:\My Games\Star Ruler\Mods\MyMod\Game Data\scripts\server\planet.as: Can't implicitly convert from 'const subSystemDef@' to 'subSystemDef@'.
line: 713, col: 4
AS Server Error in M:\My Games\Star Ruler\Mods\MyMod\Game Data\scripts\server\planet.as: Can't implicitly convert from 'const subSystemDef@' to 'subSystemDef@'.
line: 713, col: 14
AS Server Error in M:\My Games\Star Ruler\Mods\MyMod\Game Data\scripts\server\planet.as: Can't implicitly convert from 'const subSystemDef@' to 'subSystemDef@'.
line: 713, col: 24
...
I guess the problem is that the 'const' (marked blue) refers to the array object, not the individual references within the array - but what's the correct syntax to make this an (optionally const) array of const refererences? Everything i tried just threw more syntax errors.
Thank you.