#Still cannot get the power level filter for this script.

1 messages · Page 1 of 1 (latest)

hidden stag
#

I still cannot get this to work. The filters don't seem to do anything.

import { world } from "@minecraft/server"

world.events.projectileHit.subscribe(eventData => {
  const {
    source,
    projectile
  } = eventData
  if (!source.hasTag("gamer")) return;
  if (projectile != 'minecraft:arrow') return;
  const { block } = eventData.getBlockHit()
  if (block.type.id != 'minecraft:target') return;
  let power = block.getRedstonePower()
  if (power <= 10) return;
  source.runCommandAsync(`function getkey`)
})
hidden stag
#

I got that. The power level doesn't work. If I use <= or >= it doesn't run

#

If I use != it occasionally works.

#

Where would I add console.warn?

solemn bison
#

after let power

hidden stag
#

Yes

solemn bison
#
world.events.projectileHit.subscribe(async eventData => {
    const {
        source,
        projectile
    } = eventData
    if (!source.hasTag("gamer")) return;
    if (projectile.typeId != 'minecraft:arrow') return;
    const { block } = eventData.getBlockHit()
    if (block.type.id != 'minecraft:target') return;
    await null
    let power = block.getRedstonePower()
    if (power <= 10) return;
    source.runCommandAsync(`function getkey`)
})
#

the redstone power is actually on the next tick or somethin

hidden stag
#

I tried await. Didn't try adding null

#

So...question. < is always greater than and > is always less than?

#

I thought (power >= 10) was power is greater than or equal to. But it works if I use <= though.

solemn bison
#

it's a contidition in ur if statement when to return

#

so like if power <= 10 it will skip, and if not, then it continues to trigger the command

#

u can also put that in

if (power > 10) source.runCommand(`function getkey`)
hidden stag
#

Yeah. But is power <= 10 the same as saying power is less than or equal to 10?

#

Because it triggers if it's above 10

solemn bison
#

exactly...

hidden stag
#

So < is always greater than and > is always less than

solemn bison
#

yes

#

w8

#

its prob the return; that's messing u

#

when u do sth like this

#

imagine it like

#

decreasing number

#

10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0

hidden stag
#

But <= runs if the power is 10,11,12,13,14

solemn bison
#

yes

#

cus of return; there

#

it's called "guard clause"

hidden stag
#

Oh. Wtf was I thinking. Sorry

solemn bison
#

it's alr

hidden stag
#

I totally forgot the return