#Biome Tracker doesnt work and keeps detecting a new biome.

8 messages · Page 1 of 1 (latest)

serene sapphire
#

Im trying to make a biome tracker that tracks what specific biomes you have visited and how many you have visited in total.
i am currently gettiung this error message

[Server thread/ERROR]:biome_tracker.js#28: Error in 'PlayerEvents.tick': TypeError: Cannot find function add in object [object Object].

i am pretty new to java script so i would appreciate the help:
````js
const checkInterval = 20
let biomeCache = {}

PlayerEvents.loggedIn(event => {
const player = event.player
const name = player.username

let saved = player.persistentData.biomesVisited
let biomeList = []

if (saved) biomeList = JSON.parse(JSON.stringify(saved))

biomeCache[name] = new Set(biomeList)
player.persistentData.biomeCount = biomeCache[name].size
console.log(biomeCache[name])

})

PlayerEvents.tick(event => {
const player = event.player
const name = player.username

  if (player.age % checkInterval !== 0) return

const currentBiome = player.level.getBiome(player.blockPosition()).unwrapKey().get().location()
if (!currentBiome) return

if (!biomeCache[name].has(currentBiome)) {
    biomeCache.add(currentBiome)
    player.persistentData.biomesVisited = Array.from(biomeCache[name])
    player.persistentData.biomeCount = biomeCache[name].size

    player.tell(Text.green("New Biome Discovered" + currentBiome))
     player.tell(Text.green("Biome Count" + biomeCount))
}

})

winter juncoBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

jade maple
#

you are trying to call .add() on biomeCache directly, rather than calling it on biomeCache[name].

#

Oh an you also aren't increasing checkInterval anywhere in these scripts, though you would have to do that in some global tick event (ServerEvents.tick) anyway

#

^ well i suppose you probably aren't using it right now anyway since its set as a constant instead of a modifiable variable

serene sapphire
jade maple
#

try console.logging the Set, it might be that .location() returns a new object every time (if so you have to somehow turn that into a string)

serene sapphire