Advertisement

Syntax question by (relative) newbie

Started by July 13, 2012 12:15 PM
2 comments, last by Guntram 12 years, 5 months ago
Ok, this question is a bit embarassing. Back when i used to program in C a lot, i'd have told anyone asking this to rtfm, but i just didn't find anything to help with this.

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.
Making arrays of const handles isn't possible in the version of the AngelScript engine we used. It will be possible if we update to the newest engine by creating an array<const subSystemDef@>.
Advertisement
Indeed. This was unfortunately an overlooked part of the syntax in the earlier versions. Only in the latest release (2.24.0) has this been corrected to allow the declaration of arrays of const handles (after ThyReaper's bug report).

Even with the the latest version it's impossible to declare an array of const handles with the type@[] style. It's only possible with the more verbose style: array<const type@> that ThyReaper mentioned.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Woot. One reply from a maker of Star Ruler and one from the maker of Angelscript. I guess that's the best support i could have dreamed of smile.png

Now i don't really like the answer (i'd have preferred something like "just use XXXX, noob!"), but i'll try to work around this by storing the strings, not the refs, and calling getSubSystemDefByName a bit more often. And of course, i'm looking forward to the update to both AngelScript and Star Ruler (btw, i know 1.2.0.0 is out now, but obviously there's no patch for my euro 1.1.0.4. version?)

Guntram

This topic is closed to new replies.

Advertisement