#if statement weirdness

43 messages · Page 1 of 1 (latest)

drowsy helm
#

In my head if (!condition1 && !condition2) {...} should work normally... right? But noooo in KJS it somehow returns false even if the conditions are both false

ServerEvents.recipes(event => {
  // This is returning false despite the conditions being met
  if (!Platform.isLoaded('aether') && !Platform.isLoaded('reliquary')) {
    event.recipes.summoningrituals.altar('minecraft:ender_eye')
      .itemOutput('endrem:cursed_eye')
      .input([
        '4x minecraft:lightning_rod',
        '4x minecraft:amethyst_shard'
      ])
      .id('kubejs:endrem/altar/cursed_eye_fallback')
  }
  if (Platform.isLoaded('aether') && Platform.isLoaded('reliquary')) {
    event.recipes.summoningrituals.altar('minecraft:ender_eye')
      .itemOutput('endrem:cursed_eye')
      .input([
        '4x minecraft:lightning_rod',
        '4x minecraft:amethyst_shard',
        'reliquary:rending_gale',
        'aether:lightning_sword'
      ])
      .id('kubejs:endrem/altar/cursed_eye')
  }
})
grave nimbusBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

mystic salmon
#

try surrounding them in parenthases, like js if ((!bool1 && !bool2))

#

either that or js if (!(bool1 && bool2))

drowsy helm
mystic salmon
drowsy helm
#

That one works normally
Edit: Thought it was if (!bool1 && bool2) at first but I'll try that

#

Oh wait didn't see the parentheses

drowsy helm
#

Just not these

if ((!bool1 && !bool2))

if (!bool1 && !bool2)
mystic salmon
#

very odd

waxen gorge
#

What about (!(bool1) && !(bool2))

#

If that works that's still a NOR, which is what Celeste wanted originally

#

Oh wait, did Celeste actually want a NAND without realising?

#

Her original logic looks incorrect

#

If only one of the mods are loaded neither statement will trigger

drowsy helm
#

I wanted a negative and, yes...? I think? If it is what I think it is

#

But for clarity...

  • I want the if statement to return true to register the recipe when both mods are not present at the same time.
  • It must trigger and return true when one of the mods is present.
waxen gorge
#

Okay then you're original logic was correct

#

It just didn't work for some reason

waxen gorge
#

The logic that worked for you is actually incorrect and will trigger if one of the mods is present

#

You can also try (!(bool1 || bool2))

#

Which should achieve the correct output

drowsy helm
#

In this case reliquary is loaded but not aether, so the fallback all Minecraft item recipe doesn't load which isn't what I want

#

let bool1 = false
let bool2 = false

/**
 * Expected and desired if statement.
 * - Both mods must NOT be loaded at the same time for this to return true.
 * - One mod must be permitted to load for this to also return true, since the above condition is also met.
 */
if (!bool1 && !bool2) {
    console.log('Desired true!')
}

// KubeJS interprets all of these as false.
if (!bool1 && !bool2) {
    console.log('I should be returning true, but I do not. x1')
}

if ((!bool1 && !bool2)) {
    console.log('I should be returning true, but I do not. x2')
}

// KubeJS interprets this as true and functions as needed.
if (!(bool1 && bool2)) {
    console.log('Desired true!')
}
#

Oh god 4 AM brain is hitting me hard

#

Let me just edit my above messages ughghaskdflajsdf

waxen gorge
waxen gorge
#

You had it the wrong way around the entire time...

#

Close the ticket

#

We're all tired sometimes

drowsy helm
#

But I'm not sure if this is a bug in KJS or not

#

Because the browser returns true, KJS returns false

waxen gorge
#

If anything it's a bug in rhino, I doubt that'll be fixed until ichor

mystic salmon
#

if either one is false itll pass as true and itll require them both to be true for it to return true

mystic salmon
fossil mauve
#

Has Nashorn ever been used/tested? Is Rhino better?