MV (SRD HudMaker) Ternary operator using a custom object property as a condition returns errors

So I'm using SumRndmDude's Hud Maker plugin to make a custom battle UI. I have several states that operate using custom properties attached to the battler with the state via Yanfly's Buffs & States Core; for example

Code:
user.lastElement = this.item().damage.elementId;
user.noElement = "noElement";

The idea is to be able to have the same state or mechanic applied to multiple different battlers and to be able to neatly track the necessary data by attaching the relevant variables to those battlers.

I have several UI elements I want to construct using the information stored in these custom properties. My initial plan was to use Hud Maker's "Text" and "Picture EX" tools; for example, I might want a picture near an actor's portrait to indicate the element of the last spell they used. For that, my plan would be to have a picture in the Pictures/SumRndmDde/Pictures folder with the title of each element; then, I'd use a "Picture EX" hud element to represent that element using the aforementioned property:

Code:
${$gameParty.leader().lastElement ? $dataSystem.elements($gameParty.leader().lastElement) : $gameParty.leader().noElement}

Ideally, with all the pictures named correctly, this would show the picture for the user's last used element if they'd cast a spell during this fight, or a default "no element" picture otherwise.

Unfortunately, for whatever reason, whenever I try to use the existence of a custom property like this as the condition for a ternary operator in Hud Maker elements, the element simply produces an error. The error goes away if I remove the custom property condition. Does anyone have any advice as to what I might be doing wrong?
could it be that $gameParty.leader().lastElement returns a number but $gameParty.leader().noElement returns a string?

What is this.item().damage.elementId if there is no element? Is it 0? undefined? null?

Why not just return a string value or a 0 instead of $gameParty.leader().noElement?

What does the error message say?
In addition to Shaz's suggestions, it's also worth noting that $dataSystem.elements is an array, yet you're trying to call it like a function. Unless you've got some plugin that is changing this, it should be $dataSystem.elements[$gameParty.leader().lastElement] (in other words, use square brackets instead of parenthesis).

But I will second her final question to you, and ask "what does the error message say?" That's the single most important piece of information you could ever give when you're asking for help diagnosing an error. It would be even better if you were to show us a screenshot of the error in your developer console (press F8, click on "Console" up at the top, and post a screenshot of the entire window without cropping anything).
Thanks for the replies!

So, to go over what I've learned so far:

Arthran is correct, I was using $dataSystem.elements wrong by calling it like a method instead of a property. That part is no longer an issue and it's working correctly now that I'm calling it as an array.

After a lot of testing and finagling, I've managed to determine that, at least with the "text" option, I was making small syntax errors that were causing problems; at this point I've got it returning the correct strings.

Now, the remaining problems I've identified:

To reply to Shaz, abilities with no element seem to return "0". As for why I've been doing .noElement, I've had issues trying to figure out how to return anything that isn't a pre-existing string in a variable. Please forgive my inexperience; in this context, what would be the best way to return a simple catch-all "no element" string?

Currently I'm still trying to figure out how to fix the "Picture EX" side of things. As far as I can tell, it's reading the string the same way as "Text", but this particular HUD element needs to be encapsulated in apostrophes (e.g. 'string'). However, trying to encapsulate the ${} section of the string in apostrophes causes the ${} section to be treated as plain text rather than code. I can sort of finagle my way around this by renaming the pictures with awkward names that have a word at the beginning and end, but I'm wondering if there's a better way to do this?
I've had issues trying to figure out how to return anything that isn't a pre-existing string in a variable. Please forgive my inexperience; in this context, what would be the best way to return a simple catch-all "no element" string?
You could do exactly that. Simply typing "no element" or "noElement" at the end of your ternary is a string, it doesn't have to come from a variable.
You could do exactly that. Simply typing "no element" or "noElement" at the end of your ternary is a string, it doesn't have to come from a variable.
Oh, this does work! I guess my previous attempts at doing it this way must have been formatted incorrectly. So now I can simplify my ternary operator, which is good. If I can figure out how to properly encapsulate the code section, I think this'll be just about solved?

Thanks for the tip!

Original thread: https://forums.rpgmakerweb.com/threads/srd-hudmaker-ternary-operator-using-a-custom-object-property-as-a-condition-returns-errors.156421/