#why doesnt this work anymore?

1 messages · Page 1 of 1 (latest)

hollow quarry
#

world.afterEvents.itemCompleteCharge.subscribe(ev => {
const item = ev.itemStack.typeId
const player = ev.source
system.run(()=> {

    if (item === "minecraft:beef" || item === "minecraft:mutton" || item === "minecraft:porkchop" || item === "minecraft:chicken" || item === "minecraft:rabbit" || item === "minecraft:cooked_beef" || item === "minecraft:cooked_mutton" || item === "minecraft:cooked_porkchop" || item === "minecraft:cooked_chicken" || item === "minecraft:cooked_rabbit") {
        vampires_thirst(player)
        vegetarians_dismay(player)
    
    }
    else if (item === "minecraft:cooked_beef" || item === "minecraft:cooked_mutton" || item === "minecraft:cooked_porkchop" || item === "minecraft:cooked_chicken" || item === "minecraft:cooked_rabbit") {

        vegetarians_dismay(player)

    }
    else{
        vegetarians_appetite(player, item)
    }
            
})

})
this runs with an error after 1.20.1 "TypeError: cannot read property 'subscribe' of undefined"

sudden elm
#

try doing || after each and every item in the if statement

#

so item === "minecraft:beef" || item === "minecraft:mutton"

#

do that for all of them

south moth
#

they did

#

that’s why it changed to a ||test||

sudden elm
#

oh my bad, I didn't even realise that

hollow quarry
#

That fixed my problem but what about this?

#

world.afterEvents.weatherChange.subscribe((event) => {

const { dimension, lightning, raining } = event
if (lightning) {
    isRaining = true
    
} 
if (raining) {
    isRaining = true
    
}
else {
    isRaining = false

}

})

carmine canyon
#

?code block

sharp thistleBOT
#
Formatting JSON, JS

Please format your code as code-blocks! This makes the text monospaced, and has support for syntax highlighting.

The format looks like this:

for JSON
```json
{
"example": 123
}
```

for JavaScript
```js
console.log("hello world", 123) 
```

The character used here is the backtick (U+0060 ` GRAVE ACCENT). This symbol is usually at the top left of your keyboard, occupying the tilde key (~). On mobile, it will be on the second or third page of symbols.

fierce star
#

@hollow quarry like patches said, use arrays instead, looks better and it even makes you feel better

const itemArray = [
    "minecraft:mutton",
    "minecraft:porkchop",
    "minecraft:chicken",
    "minecraft:rabbit",
    "minecraft:cooked_beef",
    "minecraft:cooked_mutton",
    "minecraft:cooked_porkchop",
    "minecraft:cooked_chicken",
    "minecraft:cooked_rabbit"
];
const item = ev.itemStack.typeId
if (itemArray.includes(item)) {
}
#

^^^ much more simple too

hollow quarry
#

imma be honest i never learned how to add arrays thx