-
-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use length check to handle with
in JEI Description
#5429
use length check to handle with
in JEI Description
#5429
Conversation
JavaScript's variable accessing is buggier than my expection
Hmm, what seems to throw an exception, do you have any examples? |
The error happens within |
What about |
KubeJS seems cannot recognize this syntax. The log says:
I did some researches, and found that |
Aw damn. You could do a check on the length of text.with to see if the entry i is there. I'd prefer not to use try catch for a preventable issue. |
@@ -491,9 +491,9 @@ onEvent('jei.information', (event) => { | |||
|
|||
recipes.forEach((recipe) => { | |||
for (let i = 0; i < recipe.text.length; i++) { | |||
if (recipe.with[i]) { | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about doing something like this:
if (Object.keys(recipe).includes("with")) {
recipe.text[i] = Text.translate(recipe.text[i], recipe.with[i]);
} else {
recipe.text[i] = Text.translate(recipe.text[i]);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main issue is that the recipe.text and recipe.with arrays can be different lengths, checking whether recipe.with exists is simply if (recipe.with){...}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah alrighty 😄 Then you can do technically recipe.with && recipe.with.lenght > i
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly 👍
Co-authored-by: Niels Pilgaard Grøndahl <niels.pilgaard@hotmail.com>
But I'm still confused. In theory, |
Text.with[i] can try to access an element at an index that the array doesnt even have, which throws an exception. |
041446f
into
EnigmaticaModpacks:develop
try-catch
to handle with
in JEI Descriptionwith
in JEI Description
JavaScript's variable accessing is trickier than my expection. Errors will be reported by KubeJS at seemly completely random time.
So, instead of painstakingly debugging(I've done so, really painstaking), let's just use
try-catch
.Ported from ZZZank@2117038