Jump to content
  • Advertisement
Sign in to follow this  
Guntram

Syntax question by (relative) newbie

This topic is 2171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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@>.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!