MV SRD HUD Maker + YEP Durability Question

I just realized that I made a previous thread WAAAAY more complicated than it needed to be (sigh): sorry @caethyril. I will edit my other thread (to disregard the change in topic) & ask that it be closed since my original question was answered. I'll post my new question here.

Question:
I am using SRD HUD Maker + YEP Item Durability & would like to show the player how much durability they have left in equip slot #3 (since that's the only equipment that has durability).

What I need now is a script call to ALSO check if the durability value is <0 because YEP's unbreakable items have a value of "-1". If the value is <0, then I would like the word "Unbreakable" to replace the durability value/number shown. Does anyone know how that's done? I've spent over 12 hrs on this, have tried dozens of combinations, & still can't figure it out (but I'm sure it's maddenly simple, sigh). TIA!

ScreenShot_20230311085639.png
Try this?

var m = $gameParty.members()[0]; var o = m ? m.equips()[3] : null; o ? (o.durability < 0 ? "Unbreakable" : o.durability) : ""
I.e.
  • Get the party member in position 0 (leader);
  • If that member exists, get the item they have equipped in slot index 3 (equip type 4);
  • If that item:
    • Exists and has negative durability: return "Unbreakable".
    • Exists and does not have negative durability: return the durability value.
    • Does not exist: return a blank string, "".
I posted something similar in your previous thread, but originally made a mistake in it. I think this one will be OK, though. As you can probably tell, the multiple steps are there as failsafes to avoid crashes, e.g. due to that actor not having any item equipped in that slot. 👋
So here's the funny thing. I can actually read JS, I just can't create it (LMAO): I think b/c I can't remember all of the syntaxes until I see them (e.g. I know that adding a "?" creates an inline conditional, but I never remember to use it when I'm trying to figure out something for myself, LOL). Thx for the explanation tho 😤It may also be helpful to any others who come across this thread.

  • Here's my understanding of your suggestion (correct me if I'm wrong, plz):
  • Party member 0 (e.g. the leader) is stored in var 'm'
  • The check (condition) to see rather an item is equipped in slot #3 is stored in var 'o'
  • The check (condition) to see rather the item verified in 'o' has a durability below 0 (the string "unbreakable") or above 0 (e.g. a blank box), is in the last bit...

The prob I've had up to this pt (messing around & trying various combos of your previous suggestions) is that I'm trying to add your suggestion to the "condition box", then add a script call for variable "m" to the value box. That hasn't worked (it automatically returns an "error", but doesn't say why)... nor has anything else I've tried come close to a solution (e.g. changing it from "m" to something else, like a number or some other word). The closest I've gotten so far is adding your suggestion to a parallel global (e.g. common) event, using a numbered variable, then calling that variable from the HUD value box. The result so far has been a blank box when no armor is equipped (so, that seems to work), & when armor IS equipped, text that says [object Object] (which I assume is some kind of screwy info the HUD is getting from the "equips").

**Edit**
I found something that NEARLY works (it doesn't return a blank or "unbreakable" string, but returns "0" when there's nothing in the armor slot). I have the script below in a parallel CE, & I have a script call for var 988 in the HUD:
JavaScript:
var m = $gameParty.members()[0];
var o = m ? m.equips()[3] : null;
var s = o ? (o.durability < 0 ? "Unbreakable" : o.durability) : "";
$gameVariables.setValue(988, s)
Yep, sounds like you understand the logic behind my suggestion!

I'm trying to add your suggestion to the "condition box", then add a script call for variable "m" to the value box.
As you've discovered, that won't work. I haven't checked the plugin code, but it's very likely, given the return behaviour, that these fields all use evals. There will be some function responsible for the eval, and any var declarations within that function will only exist for that function call. I.e. the variables effectively get deleted after the eval ends.

Instead, just check the durability twice: once for condition, once for value. Condition could be:

var m = $gameParty.members()[0]; var o = m ? m.equips()[3] : null; o ? o.durability <= 20 : false
I.e. display it iff the corresponding item exists and has 20 or less durability.

Also: I use bold (and underline) formatting to emphasise key points, it doesn't mean I'm annoyed or anything like that. 👋

Spoiler: notes on your code/approach
I have the following:
JavaScript:
var m = $gameParty.members()[0];
var e = m ? m.equips()[3] : null;
e ? (m.armors().durability <0 ? "Unbreakable" : m.armors().durability) : "";
$gameVariables.setValue(988, e);
Yea, that's not gonna work as you intend. armors() is an array, and I doubt that array has a durability property. You want e.durability there instead, right? Because you want to check the durability of the item in equip slot 3? Also, just to be super clear, equip slot 3 is the fourth equip slot (because slot 0 is the first).

I would not recommend using global variables like that for "carrying" values from one place to another. It's unintuitive, hacky, and quite possibly less CPU-/RAM-efficient than simply checking things twice via SRD's plugin. 😴

There's an important difference between armors() and equips(), too:
  • equips() gets an array of weapons/armors equipped in each slot, e.g. equips()[0] always gets the item in slot 0. Empty slots are null.

  • armors() gets an array of all equipped armors...if there's only 1 armor equipped, in slot 4, then the array will only contain a single item.
So be sure to use equips() if you want to check a specific slot!
No, I didn't think you were annoyed by the way you formatted your text (though, thank you for the clarification)... I wanted to apologize b/c my friends have mentioned that when I get too focused on something, I tend to either ramble or overanalyze the situation & make a mess out of it (LOL), which can be irritating to others. A little of my history (& why I can understand script logic, but not write it well) is that I'm a "old school scripter", & most of my knowledge is spread between C+/++, C#, LUA, HTML/CSS, & the like. I've been coding longer than I care to admit (*cough* since the 90's, lol), so I can follow most script suggestions, since the formatting is similar. But since the syntax of each coding language has its own purpose (usually), it requires "relearning" coding for each, new language a person wants to use. Since I'm getting older, I don't have much interest in learning JS (though it does fascinate me), & I DO try to either figure things out on my own (via research, reverse engineering, or etc.), but sometimes I hit a wall. I know that you guys (the admins) on here are wonderful ppl, & are very good about helping others, but I feel as though there are others who need more help than I do, & so I feel bad anytime I have to ask for help... but sometimes I just need it (lol). Plus... even though I don't want to have to learn JS, I DO really enjoy learning "more ways to do one thing" (old school coder joke), & the suggestions I receive on this forum do just that!

There's nothing I can offer as thanks to all of the help you guys regularly offer (wish there was tho), other than "thanks" itself... so, again... thanks a MIL!!

P.S. The only way I know to show my appreciation to this forum is to offer sample projects to users of this forum, that demonstrate how to do various things I've incorporated into my own games (e.g. a lot of evented things, with custom graphics I've made, or similar). On that note, I'm about to finish an "Evented Projectile" sample project, which uses movement routes vs parallel processes, so that numerous projectiles can be placed on a map without causing lag. I've been trying to figure out where to upload contribution projects; Could you suggest the best forum location to do that?

**Edit**
To clarify my use of bold (&/or colored) text, it's to make something stand out; such as in my post above. It was a rather long post, & if a person just wants to "skim" to my question, the bold-type & color change makes that stand out.

I also just tried your most recent suggestion & the HUD Maker still won't accept it. It won't run anything unless it's wrapped in a ${}... so your suggestion ends up looking like:
Code:
${var m = $gameParty.members()[0]; var o = m ? m.equips()[3] : null; o ? o.durability <= 20 : false}
... meaning the HUD is trying to run it like a script call, which has produced a critical error each time (which is why I've resorted to adding your suggestions, or some variation of them (lol), to a parallel CE up to this point).

I DID try toying with the icon durability script you gave me before... attempting to change out the "some" function for something else, like "value", to attempt producing a numerical value of the durability, but with no luck. I feel like the HUD won't accept a single line of various variables, but it'll run a function. Is there anything that can be done with the following script function to change it from a boolean to something that will print out the correct alphanumeric value if the condition is met?
JavaScript:
$gameParty.members()[0].armors().some(function(armor) { return armor.durability >= 0 && armor.durability <= 20; })

To something like.............. ??
Code:
$gameParty.members()[0].armors().value(function(armor) { return armor.durability < 0 ? "Unbreakable" : ""; })
Oh! Maybe those fields are interpreted as template literals? In that case I think the "eval" would have to be a single expression, which explains the previous problems, but will make things more messy.

You could try these:
  • Condition - "does the item exist and have 20 or less durability?":

    $gameParty.members()[0] && $gameParty.members()[0].equips()[3] && $gameParty.members()[0].equips()[3].durability <= 20
  • Display value - "item durability value, Unbreakable for negative, else 0":

    ($gameParty.members()[0] && $gameParty.members()[0].equips()[3] && ($gameParty.members()[0].equips()[3].durability < 0 ? "Unbreakable" : $gameParty.members()[0].equips()[3].durability)) || 0
Same ideas as what I suggested previously, just packed into single expressions with no local vars. These use the short-circuit behaviour of logical AND/OR operators, based on JavaScript's concept of falsy values (type coercion). You could write them entirely with conditional operators (check ? ifTrue : ifFalse) instead if you prefer. 👋

If those don't work out then I think I'll leave this for someone more familiar with SRD's plugin to answer. 😴


As for the sample project, I'm not sure since I mostly stay on the Support boards, but I'm guessing you could post it:
It can always be moved if it turns out there's somewhere more suitable~
That was it!!!!! PHENOMENAL!!!!! I just had to make a slight tweak to make it blank when no armor was being worn in that slot.

For any interested in adding this to their own game............
Here is the adjusted script (for SRD's HUD Maker + YEP's Item Durability), to show how much durability is in equipment slot #4 (QED index 3), of party member 0 (aka the leader), either showing a blank box if no armor is worn, or the word "unbreakable" if the player is wearing unbreakable armor (paste it exactly as it is shown here, in the "value" slot of your HUD text box):
JavaScript:
Dur: ${($gameParty.members()[0] && $gameParty.members()[0].equips()[3] && ($gameParty.members()[0].equips()[3].durability < 0 ? "Unbreakable" : $gameParty.members()[0].equips()[3].durability)) || ""}

You can remove the "Dur:" from the beginning of the script if you don't want it to display that text. ALSO!! Any edits to this (or any other) script (such as removing the "Dur" text), made within the HUD Maker, will cause the HUD to cut off the end of the script text (don't know why), which will produce an error... meaning... you should edit the script line in a doc or text editor & C/P it from there. Once the script is inserted into the HUD maker, however, it won't change unless you try to edit it from within the HUD Maker, itself.

ScreenShot_20230313142618.png


For any who want to replicate the method used to create an icon that shows rather the party leader's #4 slot (equip index #3) armor is nearly worn / broken, HERE is the discussion on that.

Thanks a MIL @caethyril! This has been a heck of an endeavor, but it was resolved, beautifully!! I hope this will help someone else out in the future. Admins: This thread can be locked.

P.S. Thx for the forum suggestions (I'll prolly use the Tutorial Board; it sounds the closest).

Original thread: https://forums.rpgmakerweb.com/threads/srd-hud-maker-yep-durability-question.155729/