Bug - Fixed PluralValues in Javascript, and should Effect.all be one?

Obeliks

Member
When I try to access the all property of an Effect in Javascript, I get an error:


Code:
> js Effect.get("Mallowed Out").all

Script    exception: ASH function returned native Java object.

I looked into whether I should add support for PluralValue in ValueConverter.asJava, but now I'm not sure if that method should even return a PluralValue. Shouldn't it just be an ArrayValue?
Am I misunderstanding what PluralValues are supposed to be/do?
 
A PluralValue is the equivalent of a map from value -> boolean.
Internally, the data is a Java array.
It is immutable; you cannot add, delete, or modify its contents.
The keys are the data type.
The value is always true.
You can use contains(value) to check whether a value is present.
You can iterate using "foreach value in pluralvalue"
In ASH, you get one of these when you, for example, use "$items[seal tooth, turtle helmet, stolen accordion]"

An ArrayValue is the equivalent of a map from int -> value
Internally, the data is a Java array.
Its size is fixed; you cannot add or delete values.
You can change the stored values.
The key is an index.
The data is whatever you want.
You can use contains(int) to check whether the index is in range
You can iterate using "foreach index, value in array"

In ASH, "effect.get" returns a PluralValue of strings that contains every "action" that can produce that effect.

Code:
> ash $effect[Mallowed Out].all

Returned: aggregate boolean [string]
eat 1 roasted marshmallow => true
cargo effect Mallowed Out => true

This is intentional, since you can iterate over that and get the strings, one after the other, without having to care about an "index".

In the ASH runtime, all of the following are PluralValues:

effect.all
monster.attack_elements
monster.images
monster.random_modifiers
monster.sub_types

I have no opinion how Javascript should represent PluralValues.
 
When I try to access the all property of an Effect in Javascript, I get an error:


Code:
> js Effect.get("Mallowed Out").all

Script    exception: ASH function returned native Java object.

I looked into whether I should add support for PluralValue in ValueConverter.asJava, but now I'm not sure if that method should even return a PluralValue. Shouldn't it just be an ArrayValue?
Am I misunderstanding what PluralValues are supposed to be/do?
Yeah it just wants to be an array in JS
 
That's a good point.

After I wrote my comment, I thought that maybe they were like (insertion order) Sets - except you can have duplicate values. Which means my description of them as maps from value -> boolean is not correct. :)
 
@Obeliks great work on this and the exceptions PR by the way, please feel free to contribute more in future!!
 
Back
Top