#how can stop event

1 messages · Page 1 of 1 (latest)

warped quiver
#

I have this event in a function, and I want that when any if event happens, the event stops, or well the entityDie, try this but when it happens the game crashes

exotic quail
#

This code seems redundant.
id is a callback, not an System class ID

eager nacelle
#

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

exotic quail
#

Honestly, he could technically just put the event outside of the function without the system.clearRun(). And it could still work as intended.

eager nacelle
#
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

halcyon groveBOT
#
Debug Result

There are 2 errors in this [code](#1175230738346545192 message):

<repl>.js:5:10 - error TS2339: Property 'sendMessage' does not exist on type 'Entity'.

5   player.sendMessage("You Died, You loser");
           ~~~~~~~~~~~

``````ansi
<repl>.js:8:1 - error TS1005: ')' expected.

8 
  

#
Debug Result

There are 2 errors in this [code](#1175230738346545192 message):

<repl>.js:5:5 - error TS2740: Type 'Entity' is missing the following properties from type 'Player': camera, isEmoting, isFlying, isGliding, and 23 more.

5 var player= arg.deadEntity;
      ~~~~~~

``````ansi
<repl>.js:11:1 - error TS1005: ')' expected.

11 
   

eager nacelle
exotic quail
#
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)

exotic quail
#

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

exotic quail
#

I would not suggest creating a loop using a function.