AGS Development > Engine Development

Dictionary "Get" when key not present

(1/1)

Monsieur OUXX:
AGS 3.5.0 24 (I think that's Patch 4 but I'm not 100% sure)

Try this in a custom script:

--- Code: Adventure Game Studio ---void game_start(){  Dictionary* d = Dictionary.Create(eSorted);  String v = d.Get("badKey");} 

The manual says that d.Get("badKey") should return null.
Instead it generates an engine error.

Crimson Wizard:
I pushed a fix for this, and few other things. This fix will be part of a next patch, also could be downloaded here when it's ready (may need to wait an hour or so): https://cirrus-ci.com/task/6244779275059200
EDIT fixed link

Meanwhile, the workaround is probably this:

--- Code: Adventure Game Studio ---String SafeGet(this Dictionary*){    if (this.Contains("badKey"))        return this.Get("badKey");    return null;} 

Monsieur OUXX:

--- Quote from: Crimson Wizard on 17 Sep 2020, 20:25 ---I pushed a fix for this, and few other things. This fix will be part of a next patch, also could be downloaded here when it's ready (may need to wait an hour or so): https://cirrus-ci.com/task/6244779275059200
EDIT fixed link

Meanwhile, the workaround is probably this:

--- Code: Adventure Game Studio ---String SafeGet(this Dictionary*){    if (this.Contains("badKey"))        return this.Get("badKey");    return null;} 
--- End quote ---


Look, this is the function  I had written ;-D ;-D ;-D There are some similarities lol
(also I don't know what I was thinking with that "else", off it goes!)

--- Code: Adventure Game Studio ---String SafeGet(Dictionary* d,  String key){  if (!d.Contains(key)) {    return null;  } else {    return d.Get(key);  }} 

Monsieur OUXX:
FYI, I don't know if it was fixed in the same patch, but "Set" also fails when the value is null (cannot insert null in Dictionary) and it's not written in the help of the function.

Crimson Wizard:

--- Quote from: Monsieur OUXX on 01 Nov 2020, 21:15 ---FYI, I don't know if it was fixed in the same patch, but "Set" also fails when the value is null (cannot insert null in Dictionary) and it's not written in the help of the function.

--- End quote ---

Null is key or value? Key cannot be null I think, but value could be allowed probably...


EDIT: Actually it does not allow null, because Set arguments are declared as "const string", and it fails at converting null String pointer to "const string".... You may be able to pass an empty string though ("").

So basically, Dictionaries and Sets must contain valid allocated strings.

Navigation

[0] Message Index

Go to full version