Copy link to clipboard
Copied
This one is a doozy for my non-programming head. I have tried to at least define the syntax for a javascript but I just can't wrap my head around the code for the following:
- I have 3 textboxes: "Total_Equipped_Move", "Total_Packed_Move" and "Total_Equipped_Packed".
- "Total_Equipped_Move" has a value calculated from other text boxes.
- "Total_Packed_Move" has a value calculated from other text boxes.
- "Total_Equipped_Packed" has a value calculated from other text boxes.
I would like the "MoveRate" textbox to display the lesser value between "Total_Equipped_Move" and "Total_Packed_Move" unless the sum of "Total_Equipped_Packed" is 16 or greater, then output "0".
I've taken a stab at it but my output is "TEM" instead of the value of "TEM", which also means that neither follow on statements are being calculated:
var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEM < TPM) {
event.value = "TEM";
}
else if (TEM > TPM) {
event.value = "TPM";
}
else if (TEP > 16) {
event.value = "0";
}
Assistance would be greatly appreciated. Thanks in advance!
You must change the order of the comparisons.
Good grief, one more try to get it right:
var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEP > 16) {
event.value = 0;
}
else if (TEM > TPM) {
event.value = TPM;
}
else if (TEM < TPM) {
event.value = TEM;
}
Copy link to clipboard
Copied
Replace
event.value = "TEM";
with
event.value = TEM;
Copy link to clipboard
Copied
Awesome, thanks. I removed the "" from all 3 event.values. That was a goof on my part. š
However, it still does not appear to be calculating the last else/if statement.
Copy link to clipboard
Copied
The last clause can only happen if both values are equal, and larger than 16. Is that what you had in mind?
Copy link to clipboard
Copied
No, it should supersede the output of the first two values.
Copy link to clipboard
Copied
Then it should appear as the first condition, not the last one.
Copy link to clipboard
Copied
Maybe that wasn't the best explanation. Let me try again:
If TEM is < TPM, then choose TEM. If TEM is > TPM then choose TPM. If TEP is > 16, then ignore TEM and TPM and output 0.
Copy link to clipboard
Copied
Yes, I understood. See my previous advice.
Copy link to clipboard
Copied
Ah, bummer. So there's no way then. Okay, thanks for your help.
Copy link to clipboard
Copied
That's absolutely NOT what I said.
Copy link to clipboard
Copied
My apologies, I appear to have misunderstood you. I see, after re-reading, that you were saying that the order of the comparisons was the issue, which is what Bernd, below, said. Thanks again and my bad for misunderstanding.
Copy link to clipboard
Copied
You must change the order of the comparisons.
Copy link to clipboard
Copied
So, like this?
var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEM < TPM) {
event.value = TEM;
}
else if (TEM > TPM) {
event.value = TPM;
}
else if (TEP > 16) {
event.value = 0;
}
Copy link to clipboard
Copied
I can't see any change.
Copy link to clipboard
Copied
Ooof, my bad. Long day already!
var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEP > 16) {
event.value = "0";
}
else if (TEM > TPM) {
event.value = "TPM";
}
else if (TEM < TPM) {
event.value = TEM;
}
Copy link to clipboard
Copied
Good grief, one more try to get it right:
var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEP > 16) {
event.value = 0;
}
else if (TEM > TPM) {
event.value = TPM;
}
else if (TEM < TPM) {
event.value = TEM;
}
Copy link to clipboard
Copied
That worked! Thank you!!!