#Confusion with .getTags with the Equippable Component

1 messages · Page 1 of 1 (latest)

timber raft
#

I have absolutely no clue why I did this and why it works, and why changing it makes it not work.

const equipment = player.getComponent("minecraft:equippable");
    if (equipment.getEquipment(EquipmentSlot.Head) != undefined && equipment.getEquipment(EquipmentSlot.Head).getTags().find(tag => tag.startsWith('runecraft:armor_tier'))) {

        player.__totalArmor += equipment.getEquipment(EquipmentSlot.Head).getTags().find(tag => tag.startsWith('runecraft:armor_tier'))[equipment.getEquipment(EquipmentSlot.Head).getTags().find(tag => tag.startsWith('runecraft:armor_tier')).length - 1]
    }```

The contents inside of the if statement is pretty much the same thing, the only difference being the 2nd part has .length - 1. if I remove either parts, the values bug out and are incorrect. Does anyone know why this is happening? They are identical and I don't see why I duplicated them.

```js
player.__totalArmor += equipment.getEquipment(EquipmentSlot.Head).getTags().find(tag => tag.startsWith('runecraft:armor_tier'))[equipment.getEquipment(EquipmentSlot.Head).getTags().find(tag => tag.startsWith('runecraft:armor_tier')).length - 1]```

vs 

```js
player.__totalArmor += equipment.getEquipment(EquipmentSlot.Head).getTags().find(tag => tag.startsWith('runecraft:armor_tier')).length - 1```
#

It's just searching for the tag on the item that is "runecraft:armor_tier" and subtracting it's length - 1 to get the number at the end. Example full tag would be something like "runecraft:armor_tier5" and it would just add 5 to player.__totalArmor

strange saddle
#

.length is just the length of the string- you’d want to use .slice(-1) to get the last character in the string

#

Don’t forget to convert it to a number before adding it

timber raft
#

Do you know why the first one with pretty much a duplicate works and why the other one doesn't?

#

Second one turns the value to like 21 or 23

#

Instead of just 3

strange saddle
#

Cuz you’re accessing the character itself

#

Second is just the length of the string which is a number, then removing 1