Noob: Checking Arrays

Hi! Using Harlowe for the first time ever today. I am not much of a coder so please bare with me.

I want to check an array to see what type Essence is set to, and then increase the resourceEssence that corresponds with what essence is active. I’m currently doing this with too many if statements, but I’m sure there’s a better way to do this? I might want to add to the array later on and this seems cumbersome.

(set: $essenceType to
(a:"Air","Earth","Fire","Water"))

(if: $essenceType is "air")[(set: $resourceAir to +1)]
(if: $essenceType is "earth")[(set: $resourceEarth to +1)]
(if: $essenceType is "fire")[(set: $resourceFire to +1)]
(if: $essenceType is "water")[(set: $resourceWater to +1)]

What your code appears to be doing is creating an array called $essenceType - ie. the entire group of types is collectively called $essenceType, and none of your if statements will check true. Can you explain the circumstances under which you want the essence type to change?

If I understand the basis of your question & example you want to randomly select an Element from a list of possible Elements, and then based on the Element selected increase one of four numeric counters.

The following solution uses the (either:) macro combined with the Spread Operator ... to randomly select one of the items contained within an Array, the selected item is stored within a Temporary Variable.
The solution then uses a series of (if:), (else-if:), and (else:) macros to determine which Element was randomly selected, and then uses a (set:) macro to increment a counter variable.
(untested code)

(set: _essenceType to (either: ...(a: "Air", "Earth", "Fire", "Water")))
(if: _essenceType is "Air")[(set: $resourceAir to it + 1)]
(else-if: _essenceType is "Earth")[(set: $resourceEarth to it + 1)]
(else-if: _essenceType is "Fire")[(set: $resourceFire to it + 1)]
(else:)[(set: $resourceWater to it + 1)]

note: String value comparison is case-sensitive, so the case of each letter being compared is important.
eg. The String values "Air" and "air" are not equal, because one has an upper case A and the other has a lower case a.