#Why is not a Function? [SOLVED]

1 messages · Page 1 of 1 (latest)

upper crag
#
world.afterEvents.entitySpawn.subscribe(({ entity }) => {
    const { typeId } = entity

    if (typeId === `minecraft:item`) {
        const itemStack = entity.getComponent('item').itemStack

        if (itemStack.typeId === "ch:buffed_soulless_knight_sword") {

            const { dimension, location } = entity
            const vel = entity.getVelocity()
            const velMultiplier = 2
            for (let i = 0; i < itemStack.amount; i++) {
                let itemGround = dimension.spawnEntity(`ch:buffed_sk_sword_ground`, {x: location.x, y: location.y+0.5, z: location.z});
                itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
                itemGround.applyImpulse({ x: vel.x * velMultiplier, y: vel.y * velMultiplier*2, z: vel.z * velMultiplier })
            }
            entity.remove()
        }
    }
});```

  ```js
itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});``` is not a function in log error, why?
forest arrowBOT
#
Debug Result

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

<repl>.js:5:27 - error TS2532: Object is possibly 'undefined'.

5         const itemStack = entity.getComponent('item').itemStack
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~

``````ansi
<repl>.js:14:44 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

14                 itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
                                              ~~~~~~

  @minecraft/server.d.ts:4204:15
    4204         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.

``````ansi
<repl>.js:14:70 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

14                 itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
                                                                        ~~~~~~

  @minecraft/server.d.ts:4204:15
    4204         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.

forest arrowBOT
# upper crag ```js world.afterEvents.entitySpawn.subscribe(({ entity }) => { const { type...
Debug Result

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

<repl>.js:1:1 - error TS2304: Cannot find name 'itemGround'.

1 itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
  ~~~~~~~~~~

``````ansi
<repl>.js:1:28 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

1 itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
                             ~~~~~~

  @minecraft/server.d.ts:4204:15
    4204         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.

``````ansi
<repl>.js:1:54 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

1 itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
                                                       ~~~~~~

  @minecraft/server.d.ts:4204:15
    4204         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.

upper crag
fallow anchor
upper crag
#

using this
const player = world.getPlayers()

fallow anchor
#

ok