JaylyDev/ScriptAPI

JaylyDB - functions stopped working

sircurse opened this issue · 11 comments

Describe the bug
The both functions get(key) and has(key) is not working.

can you provide more information about your problem?

image
this is the db created with my value
and this is the script to return that value
image

and it is returning undefined:
image

just noticed that the delete() is also not working.

just noticed that the delete() is also not working.

delete works well but its not synced with client so you cen look at that UI, also i thing you are not setting the value maybe thats why its undefined,
can you provide whole code where you use that database?

well it was working before the update, now the delete is doing nothing and no error at all. the code is below:

import { world, system, ItemStack } from "@minecraft/server";
import { radiusCheck, addQuestItem } from "../../system/functions";
import { JaylyDB } from "../../system/jaylydb";

let prize_table = [
  // loc.x/loc.y/loc.z / questname / isquestItem / prizeitem / quantityitem / loreMSG / keepOnDeath TRUE OR FALSE / isprizeMoney / quantityMoney / requiredLVL / custommsgFeedback / 
     [2168, 110, -1694, "enchantedbook", 1, "minecraft:enchanted_book", 1, "0", false, 0, 0, 0, "Você acaba de encontrar um §l§6Livro Encantado§r!"],
     [1966, 42, -381, "desertquest1", 0, "0", 0, "0", false, 1, 200, 20, "0"],
     [1966, 42, -374, "desertquest2", 1, "awp:iron_shield", 1, "\nEste escudo já pertenceu\na um grande §l§6Herói!§r§f", false, 0, 0, 20, "§6Você acaba de encontrar um §l§6Iron Shield§r!"],
     [2321, 76, -1422, "spell_scrolls2", 1, "awp:spell_parchment", 1, "\nEsse pergaminho contém:\n§l§6> Inquebrável III >§r§f", false, 0, 0, 0, "Você encontrou um §l§6Pergaminho de Encantamento§r!"],
     [0, 0, 0, "questname", 0, "xxx", 0, "\nxxxxx\nxxxx §l§6xxxxx§r§f", false, 0, 0, 0, "xxxxxx §l§6xxxxxx§r!"],
     [0, 0, 0, "questname", 0, "xxx", 0, "\nxxxxx\nxxxx §l§6xxxxx§r§f", false, 0, 0, 0, "xxxxxx §l§6xxxxxx§r!"],
     [0, 0, 0, "questname", 0, "xxx", 0, "\nxxxxx\nxxxx §l§6xxxxx§r§f", false, 0, 0, 0, "xxxxxx §l§6xxxxxx§r!"],
     [0, 0, 0, "questname", 0, "xxx", 0, "\nxxxxx\nxxxx §l§6xxxxx§r§f", false, 0, 0, 0, "xxxxxx §l§6xxxxxx§r!"]
   ]

export function prizeChest(player) {

  for (let i = 0; i < prize_table.length; i++) {
    if (radiusCheck(player,prize_table[i][0],prize_table[i][1],prize_table[i][2],2)) {
      const chestdb = new JaylyDB(prize_table[i][3], false);
      const hasQuest = chestdb.get(player.id);
      let value = chestdb.get(player.id);
      player.sendMessage(`chest value ${value}`)
      //chestdb.delete(player.id);


      if (!hasQuest) {
        if (player.level >= prize_table[i][11]) { // check if player have enought level

          if (prize_table[i][4] === 1) { // check if has item as prize
            addQuestItem(player, prize_table[i][5], prize_table[i][6], prize_table[i][7], prize_table[i][8])
            player.sendMessage(`${prize_table[i][12]}`);
          }
  
          if (prize_table[i][9] === 1) { // check if has money as prize
            Number.prototype.format = function(){
              return this.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
            };
            addQuestItem(player, "awp:crystal_coin", prize_table[i][10], "0", false)
            player.sendMessage(`§6Você encontrou §l§2B$ ${(prize_table[i][10]*100).format()}§r!`);
          }
          chestdb.set(player.id, player.name);  // Comment for tests

        } else {
          player.sendMessage(`§lÉ necessário §6level ${prize_table[i][11]}§r§l para abrir esse baú.`);
        }
      } else {
        player.sendMessage(`§l§cVocê já completou essa quest.`);
      }
      break;
    }
  }
};

it works to add the db entry, the only problem is when it comes to manage an existing entry (has, get and delete).
btw which version should I use now? because I m using the 1.20.0, but if I change to the 1.20.10 not even to create a new entry it is working...

I am not JaylyDB specialist but i am sure you not using JaylyDB in way how you should, JaylyDB shouln't create new instances so every time, i am not sure if i can help you at this moment

so using the new version it works just fine if I create a new db, so I m able to manage this new db recently created. But I cannot manage the old DBs, it returns the following error:

Salt: undefined 
Error: expecting property name 
    at <input>:1
    at parse (native)
    at parse (world/system/jaylydb.js:68)
    at updateParticipants (world/system/jaylydb.js:98)
    at JaylyDB (world/system/jaylydb.js:123)
    at prizeChest (world/events/quests/quest_prize.js:21)
    at <anonymous> (world/scriptevents.js:136)

[2023-07-12 23:33:16:074 ERROR] [Scripting] Error: Failed to load data. Please check content log file for more info.
    at CreateCrashReport (world/system/jaylydb.js:58)
    at parse (world/system/jaylydb.js:71)
    at updateParticipants (world/system/jaylydb.js:98)
    at JaylyDB (world/system/jaylydb.js:123)
    at prizeChest (world/events/quests/quest_prize.js:21)
    at <anonymous> (world/scriptevents.js:136)

So my question is, what is the correct procedure to update the db when there is a minecraft update? Because the old script 1.20.0 just doenst work anymore, the new script works fine but I completely lose the access to manage the old DBs created.

Judging from content log it seems like you’re using a relatively old jaylydb, AFAIK there isn’t a way to migrate directly from a really old version of jaylydb to current. I’ll try to make a script that migrates it.

is version version = "1.0.7" to "1.1.0" that old?
it was just one version before (1.20.0 to 1.20.10). but definitely a script to migrate would be awesome for sure. Luckily my DB was not that big already but I imagine in a future update if this issue happens again we need to manage a way to migrate it.

I was able to replicate this issue, I'll make a migration script and hope to push th to jaylydb v1.1.2