#how can stop event
1 messages · Page 1 of 1 (latest)
This code seems redundant.
id is a callback, not an System class ID
make sure system.run(id) -> here id should be a valid run id, if its purposeless then remove it
runcommand async has a / . slashes are not allowed i think
what u doing
function
register event
same function again
register event and so on
Honestly, he could technically just put the event outside of the function without the system.clearRun(). And it could still work as intended.
world.afterEvents.entityDie.subscribe(arg=>{
/**
* @type {Player}
**/
var player= arg.deadEntity;
if(player.typeId==="minecraft:player"){
player.sendMessage("You Died, You loser");
}
}
this should be enough
There are 2 errors in this [code](#1175230738346545192 message):
[36m<repl>.js[0m:[33m5[0m:[33m10[0m - [31merror[0m[30m TS2339: [0mProperty 'sendMessage' does not exist on type 'Entity'.
[7m5[0m player.sendMessage("You Died, You loser");
[7m [0m [31m ~~~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m8[0m:[33m1[0m - [31merror[0m[30m TS1005: [0m')' expected.
[7m8[0m
[7m [0m [31m[0m
There are 2 errors in this [code](#1175230738346545192 message):
[36m<repl>.js[0m:[33m5[0m:[33m5[0m - [31merror[0m[30m TS2740: [0mType 'Entity' is missing the following properties from type 'Player': camera, isEmoting, isFlying, isGliding, and 23 more.
[7m5[0m var player= arg.deadEntity;
[7m [0m [31m ~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m11[0m:[33m1[0m - [31merror[0m[30m TS1005: [0m')' expected.
[7m11[0m
[7m [0m [31m[0m
shut up
if you want to add additional IF conditions, I suggest just doing a return statement or something.
let boolean1 = false
let boolean2 = true
world.afterEvents.entityDie.subscribe(arg=>{
let player = arg.deadEntity;
if(player.typeId==="minecraft:player" && boolean1 && boolean2){
player.sendMessage("You Died, You loser");
}
}
//you can toggle the booleans on other event.
//use Map() for multiplayer support
try not to think too hard, and maybe look at the problem from a different perspective.
Also if you're curious, the appropriate way to stop the event listener is to do: world.afterEvents.entityDie.unsubscribe(id) not system.clearRun(id)
ohhh
In JavaScript, the memory used to record the order of function activations is called the "call stack." If you continuously build a call stack without releasing it, it will eventually lead to a stack overflow. A stack overflow occurs when the call stack reaches its maximum capacity, causing the program to crash.
That explains your crashing issue
i just do like that
works
I would not suggest creating a loop using a function.