#what is bad?

1 messages · Page 1 of 1 (latest)

lean creek
#

i don't underterstan what is bad in this code

upbeat hamletBOT
#
Debug Result

JavaScript/TypeScript code blocks not detected in [message](#1088679208584233010 message).
You can either send the script in code block highlighted in JS format:

world.sendMessage("Hello World")

Or Send an attachment end in .js to debug the file.

zealous gyro
#
import { world, Player } from "@minecraft/server";
import { system } from "@minecraft/server";

const score = world.scoreboard;
const obj = score.addObjective("Muertes", "Muertes");
world.events.entityDie.subscribe(eventData => {
  const entity = eventData.deadEntity;
  if (entity.typeId === "minecraft:player") {
    const name = (entity as Player).name;
    const currentScore = player.scoreboard.getScore(obj);
    player.scoreboard.setScore( obj, currentScore + 1);
    
    if (currentScore + 1 >= 3) {
      system.runCommandAsync(`gamemode spectator ${name}`);
      system.runCommandAsync(`kick ${name}`);
    }
  }
});
upbeat hamletBOT
#
Debug Result

There are 5 errors in this [code](#1088679208584233010 message):

<repl>.js:9:25 - error TS2339: Property 'name' does not exist on type 'Entity'.

9     const name = entity.name;
                          ~~~~
<repl>.js:10:26 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

10     const currentScore = player.scoreboard.getScore(obj);
                            ~~~~~~

  @minecraft/server.d.ts:3318:15
    3318         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.
<repl>.js:11:5 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

11     player.scoreboard.setScore( obj, currentScore + 1);
       ~~~~~~

  @minecraft/server.d.ts:3318:15
    3318         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.
<repl>.js:14:14 - error TS2339: Property 'runCommandAsync' does not exist on type 'System'.

14       system.runCommandAsync(`gamemode spectator ${name}`);
                ~~~~~~~~~~~~~~~
<repl>.js:15:14 - error TS2339: Property 'runCommandAsync' does not exist on type 'System'.

15       system.runCommandAsync(`kick ${name}`);
                ~~~~~~~~~~~~~~~

#
Debug Result

There are 5 errors in this [code](#1088679208584233010 message):

<repl>.js:9:29 - error TS8016: Type assertion expressions can only be used in TypeScript files.

9     const name = (entity as Player).name;
                              ~~~~~~
<repl>.js:10:26 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

10     const currentScore = player.scoreboard.getScore(obj);
                            ~~~~~~
<repl>.js:11:5 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

11     player.scoreboard.setScore( obj, currentScore + 1);
       ~~~~~~
<repl>.js:14:14 - error TS2339: Property 'runCommandAsync' does not exist on type 'System'.

14       system.runCommandAsync(`gamemode spectator ${name}`);
                ~~~~~~~~~~~~~~~
<repl>.js:15:14 - error TS2339: Property 'runCommandAsync' does not exist on type 'System'.

15       system.runCommandAsync(`kick ${name}`);
                ~~~~~~~~~~~~~~~

blissful jasperBOT
#
thuuh

discord is not collaborating with me, but basically, you used a variable called player without even having defined it, and the runCommandAsync method is from the world constant and not from the system constant, apart from that it would be easier for you use the runCommandAsync directly on the entity using the @s selector

lean creek
#
import { system } from "@minecraft/server";

const score = world.scoreboard;
const obj = score.addObjective("Muertes", "Muertes");
world.events.entityDie.subscribe(eventData => {
  const entity = eventData.deadEntity;
  if (entity.typeId === "minecraft:Player") {
    const name = 
      Player.name;
    const currentScore = Player.scoreboard.getScore(obj);
    Player.scoreboard.setScore( obj, currentScore + 1);
    
    if (currentScore + 1 >= 3) {
      entity.runCommandAsync(`gamemode spectator ${name}`);
      entity.runCommandAsync(`kick ${name}`);
    }
  }
});```
blissful jasperBOT
#
thuuh

this will not work as Player is a class not an object

zealous gyro
#
import { world } from "@minecraft/server";
import { system } from "@minecraft/server";

const score = world.scoreboard;
const obj = score.addObjective("Muertes", "Muertes");
world.events.entityDie.subscribe(eventData => {
  const entity = eventData.deadEntity;
  if (entity.typeId === "minecraft:player") {
    const name = entity.name;
    const currentScore = entity.scoreboard.getScore(obj);
    entity.scoreboard.setScore( obj, currentScore + 1);
    
    if (currentScore + 1 >= 3) {
      entity.runCommandAsync(`gamemode spectator @s`);
      entity.dimension.runCommandAsync(`kick ${name}`);
    }
  }
});
blissful jasperBOT
#
thuuh

actually the runCommandAsync method is from the Dimension class and not from the world constant

blissful jasperBOT
#
thuuh

press and hold the message (or press the three dots in the corner), go to apps and debug (stable)

upbeat hamletBOT
#
Debug Result

There is 1 error in this [code](#1088679208584233010 message):

<repl>.js:9:25 - error TS2339: Property 'name' does not exist on type 'Entity'.

9     const name = entity.name;
                          ~~~~

blissful jasperBOT
#
thuuh

this error is not true, it just occurs because the name property only exists in the Player class and not in the Entity class

upbeat hamletBOT
#
Debug Result

There is 1 error in this [code](#1088679208584233010 message):

<repl>.js:9:25 - error TS2339: Property 'name' does not exist on type 'Entity'.

9     const name = entity.name;
                          ~~~~

#
Debug Result

JavaScript/TypeScript code blocks not detected in [message](#1088679208584233010 message).
You can either send the script in code block highlighted in JS format:

world.sendMessage("Hello World")

Or Send an attachment end in .js to debug the file.

pale quail
#

You have player.scoreboard in there, but you never say what “player” is

#

You need to change player to entity

#
import { system , world } from "@minecraft/server";

const score = world.scoreboard;
const obj = score.addObjective("Muertes", "Muertes");
world.events.entityDie.subscribe(eventData => {
  const entity = eventData.deadEntity;
  if (entity.typeId === "minecraft:player") {
    const name = entity.name;
    const currentScore = entity.scoreboard.getScore(obj);
    entity.scoreboard.setScore( obj, currentScore + 1);
    
    if (currentScore + 1 >= 3) {
      entity.runCommandAsync(`gamemode spectator ${name}`);
      entity.runCommandAsync(`kick ${name}`);
    }
  }
}); ```
#

@lean creek

upbeat hamletBOT
#
Debug Result

JavaScript/TypeScript code blocks not detected in [message](#1088679208584233010 message).
You can either send the script in code block highlighted in JS format:

world.sendMessage("Hello World")

Or Send an attachment end in .js to debug the file.

#
Debug Result

There are 3 errors in this [code](#1088679208584233010 message):

<repl>.js:8:25 - error TS2339: Property 'name' does not exist on type 'Entity'.

8     const name = entity.name;
                          ~~~~
<repl>.js:13:14 - error TS2339: Property 'runCommandAsync' does not exist on type 'System'.

13       system.runCommandAsync(`gamemode spectator ${name}`);
                ~~~~~~~~~~~~~~~
<repl>.js:14:14 - error TS2339: Property 'runCommandAsync' does not exist on type 'System'.

14       system.runCommandAsync(`kick ${name}`);
                ~~~~~~~~~~~~~~~

#
Debug Result

There is 1 error in this [code](#1088679208584233010 message):

<repl>.js:8:25 - error TS2339: Property 'name' does not exist on type 'Entity'.

8     const name = entity.name;
                          ~~~~

lean creek
#
import { world } from "@minecraft/server";
import { system } from "@minecraft/server";

const score = world.scoreboard;
const obj = score.addObjective("Muertes", "Muertes");
world.events.entityDie.subscribe(eventData => {
  const entity = eventData.deadEntity;
  if (entity.typeId === "minecraft:Player") {
    const name = 
      Player.name;
    const currentScore = entity.scoreboard.getScore(obj);
    entity.scoreboard.setScore( obj, currentScore + 1);
    
    if (currentScore + 1 >= 3) {
      entity.runCommandAsync(`gamemode spectator ${name}`);
      entity.runCommandAsync(`kick ${name}`);
    }
  }
});```
pale quail
#

No that won’t work

lean creek
pale quail
lean creek
pale quail
#

On pc, right click on the messages then click the three dots, then go to apps, then click debug (stable)

upbeat hamletBOT
#
Debug Result

JavaScript/TypeScript code blocks not detected in [message](#1088679208584233010 message).
You can either send the script in code block highlighted in JS format:

world.sendMessage("Hello World")

Or Send an attachment end in .js to debug the file.

#
Debug Result

JavaScript/TypeScript code blocks not detected in [message](#1088679208584233010 message).
You can either send the script in code block highlighted in JS format:

world.sendMessage("Hello World")

Or Send an attachment end in .js to debug the file.

pale quail
#

Holdon lemme do it

#
import { world } from "@minecraft/server";
import { system } from "@minecraft/server";

const score = world.scoreboard;
const obj = score.addObjective("Muertes", "Muertes");
world.events.entityDie.subscribe(eventData => {
  const entity = eventData.deadEntity;
  if (entity.typeId === "minecraft:Player") {
    const name = 
      Player.name;
    const currentScore = entity.scoreboard.getScore(obj);
    entity.scoreboard.setScore( obj, currentScore + 1);
    
    if (currentScore + 1 >= 3) {
      entity.runCommandAsync(`gamemode spectator ${name}`);
      entity.runCommandAsync(`kick ${name}`);
    }
  }
});```
upbeat hamletBOT
#
No Errors

No errors in [code](#1088679208584233010 message)

lean creek
#

gooooood

pale quail
#

This wouldn’t work anyway

#

No it won’t work

#

@lean creek Player.name will not get you the player. It will get you the class called Player

#

Use the thing that I sent

#

@lean creek use this:

#
import { system , world } from "@minecraft/server";

const score = world.scoreboard;
const obj = score.addObjective("Muertes", "Muertes");
world.events.entityDie.subscribe(eventData => {
  const entity = eventData.deadEntity;
  if (entity.typeId === "minecraft:player") {
    const name = entity.name;
    const currentScore = entity.scoreboard.getScore(obj);
    entity.scoreboard.setScore( obj, currentScore + 1);
    
    if (currentScore + 1 >= 3) {
      entity.runCommandAsync(`gamemode spectator ${name}`);
      entity.runCommandAsync(`kick ${name}`);
    }
  }
}); ```
lean creek
pale quail
#

And once you’ve added the ```js, the code should change colours

pale quail
#

Anyway did you try the script I sent

lean creek
lean creek
#

I don't understand what happens with GetScore

#
import { system , world } from "@minecraft/server";

const score = world.scoreboard;
const obj = score.addObjective("Muertes", "Muertes");
score.setObjectiveAtDisplaySlot("sidebar", { objective: obj })
world.events.entityDie.subscribe(eventData => {
  const entity = eventData.deadEntity;
  if (entity.typeId === "minecraft:player") {
    const name = entity.name;
    const currentScore = entity.scoreboard.getScore(obj);
    entity.scoreboard.setScore( obj, currentScore + 1);
    
    if (currentScore + 1 >= 3) {
      entity.runCommandAsync(`gamemode spectator ${name}`);
      entity.runCommandAsync(`kick ${name}`);
    }
  }
}); ```
#

I made a modification to be displayed on the side of the screen is the only change (line 5)

pale quail
#

Does it display it properly?

upbeat hamletBOT
#
Debug Result

There is 1 error in this [code](#1088679208584233010 message):

<repl>.js:9:25 - error TS2339: Property 'name' does not exist on type 'Entity'.

9     const name = entity.name;
                          ~~~~

pale quail
#

Just wondering if your obj thing is working properly or not

#

Ignore that

pale quail
lean creek
upbeat hamletBOT
#
No Errors

No errors in [code](#1088679208584233010 message)

lean creek
pale quail
#

hm

#

well this is the closest I could get

#
const score = world.scoreboard;
const obj = score.addObjective("Deaths", "Deaths");
score.setObjectiveAtDisplaySlot("sidebar", { objective: obj })
world.events.entityDie.subscribe(eventData => {
    const { deadEntity } = eventData
    if (deadEntity.typeId == "minecraft:player") {
        const name = deadEntity.name;
        const entityScoreboard = deadEntity.scoreboard
        const currentScore = world.scoreboard.getScore(obj, entityScoreboard);
        world.scoreboard.setScore(obj, entityScoreboard, currentScore + 1);
        if (currentScore + 1 >= 3) {
            deadEntity.runCommandAsync(`gamemode spectator ${name}`);
            deadEntity.runCommandAsync(`kick ${name}`);
        }
    }
})```
#

so you can't run getScore on entities

#

you needa get the entity's scoreboard id and use that in the getScore

#

but it's not working for me

#

this is on the right track, but i don't really have time to finish

#

sorry bout that

upbeat hamletBOT
#
Debug Result

There are 3 errors in this [code](#1088679208584233010 message):

<repl>.js:7:33 - error TS2339: Property 'name' does not exist on type 'Entity'.

7         const name = deadEntity.name;
                                  ~~~~
<repl>.js:9:58 - error TS2345: Argument of type '{ objective: ScoreboardObjective; }' is not assignable to parameter of type 'ScoreboardObjective'.
  Object literal may only specify known properties, and 'objective' does not exist in type 'ScoreboardObjective'.

9         const currentScore = world.scoreboard.getScore({ objective: obj }, entityScoreboard);
                                                           ~~~~~~~~~~~~~~
<repl>.js:10:37 - error TS2345: Argument of type '{ objective: ScoreboardObjective; }' is not assignable to parameter of type 'ScoreboardObjective'.
  Object literal may only specify known properties, and 'objective' does not exist in type 'ScoreboardObjective'.

10         world.scoreboard.setScore({ objective: obj }, entityScoreboard, currentScore + 1);
                                       ~~~~~~~~~~~~~~