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?
#Why is not a Function? [SOLVED]
1 messages · Page 1 of 1 (latest)
Debug Result
There are 3 errors in this [code](#1194534438764285953 message):
[36m<repl>.js[0m:[33m5[0m:[33m27[0m - [31merror[0m[30m TS2532: [0mObject is possibly 'undefined'.
[7m5[0m const itemStack = entity.getComponent('item').itemStack
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m14[0m:[33m44[0m - [31merror[0m[30m TS2552: [0mCannot find name 'player'. Did you mean 'Player'?
[7m14[0m itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
[7m [0m [31m ~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m4204[0m:[33m15[0m
[7m4204[0m class Player extends Entity {
[7m [0m [36m ~~~~~~[0m
'Player' is declared here.
``````ansi
[36m<repl>.js[0m:[33m14[0m:[33m70[0m - [31merror[0m[30m TS2552: [0mCannot find name 'player'. Did you mean 'Player'?
[7m14[0m itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
[7m [0m [31m ~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m4204[0m:[33m15[0m
[7m4204[0m class Player extends Entity {
[7m [0m [36m ~~~~~~[0m
'Player' is declared here.
Debug Result
There are 3 errors in this [code](#1194534438764285953 message):
[36m<repl>.js[0m:[33m1[0m:[33m1[0m - [31merror[0m[30m TS2304: [0mCannot find name 'itemGround'.
[7m1[0m itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
[7m [0m [31m~~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m1[0m:[33m28[0m - [31merror[0m[30m TS2552: [0mCannot find name 'player'. Did you mean 'Player'?
[7m1[0m itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
[7m [0m [31m ~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m4204[0m:[33m15[0m
[7m4204[0m class Player extends Entity {
[7m [0m [36m ~~~~~~[0m
'Player' is declared here.
``````ansi
[36m<repl>.js[0m:[33m1[0m:[33m54[0m - [31merror[0m[30m TS2552: [0mCannot find name 'player'. Did you mean 'Player'?
[7m1[0m itemGround.setRotation({x: player.getRotation().x, y:player.getRotation().y});
[7m [0m [31m ~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m4204[0m:[33m15[0m
[7m4204[0m class Player extends Entity {
[7m [0m [36m ~~~~~~[0m
'Player' is declared here.
try in game
wdym? I did, the "is not a function" error is from content log
there is no player variable in your code
its defined in other part on the code
using this
const player = world.getPlayers()
ok