#how to catch error and send message
1 messages · Page 1 of 1 (latest)
Wrap in trycatch
not familiar with that
do you have an example?
like this
try {
//code
} catch ( error ) {//send message}
Your error shows the name of the identifier without the underscore at the end or the appending hex_name? Are you certain that the block of code you shared is where the error is stemming from?
yeah
i am making killed players drop there heads but if they don't have one the error shows up
any way i fixed that
world.afterEvents.entityDie.subscribe(event => {
const player = event.deadEntity
if (player.typeId != "minecraft:player") return;
const name = player.nameTag
let hex_name = '';
for (let i = 0; i < name.length; i++){hex_name += name.charCodeAt(i).toString(16)}
try {
const ind = "mba:item_head_" + hex_name
const head = new mc.ItemStack(ind, 1);
player.dimension.spawnItem(head, player.location);
} catch ( error ) {
world.sendMessage(`§c${name}\'s head dosn\'t exist in the pack`)
}
});
the full error is
In the resource pack, does that item exist?
no i deleted it so i can test staff : )
If it doesn't exist then you can't spawn it.
yeah that's why i need to catch the error and send a message that the player head dosn't exist in the pack
Ah, I see. Well the block of code above has a try/catch wrapped around it so that should do the job.
yeah i said that i fixed that
Didn't see that