#Help

1 messages · Page 1 of 1 (latest)

lunar monolith
#

if I remember correctly, you can no longer get if a item is undefined

stiff merlin
#

the thing is thou, its not undefined

#

im able to use it

lunar monolith
#

oh

#

hmm

stiff merlin
hearty surge
#

JSON.stringify() will always return {} into any native class (Item, Entity, Block, Player, etc.). That's the behavior on Minecraft itself

You need some deep copy to allow console return as an object

stiff merlin
#

how would i do so?

hearty surge
#

Reconstruct the item data into new object

stiff merlin
#

the entire thing?

hearty surge
#

Yes

stiff merlin
#

damn

#

so i would have to recreate the functions to? so like getComponent?

#

@hearty surge

hearty surge
hearty surge
stiff merlin
#

So how would i use this?

#

just deepCopy(src)?

hearty surge
#
console.warn(JSON.stringify(deepCopy(item)))
stiff merlin
#

Ok

#

Thanks so much!

hearty surge
#

Np

stiff merlin
#

@hearty surge sorry to bother again but now im getting this error

hearty surge
#

Don't use deepCopy

#

addItem need real/native Item class, not cloned Item class as object

stiff merlin
#

damn it

#

do you have any idea lol?

hearty surge
#

Use deepCopy when you want to console out the data, otherwise, just do normal

stiff merlin
#

but would it work? its returning {} for the data

hearty surge
#

Mojang change how JSON.stringify works, by always returning {} every native class, even tho they have all the data

stiff merlin
#

so visually it shows {} but it has the data in it correct?

hearty surge
#

That's why you always got {}, but the code still run perfectly

stiff merlin
#

Oh ok

#

damn

#

alright thanks for your time again

hearty surge
#

They purposely hide it

stiff merlin
#

why?

hearty surge
#

Idk

stiff merlin
#

weird

#

alright that should be all

stiff merlin
#

@hearty surge another thing, my countdown system will not work, like its saying that it is but the score is not changing

#

system.runInterval(() => {
    let currentAuctions = world.scoreboard.getObjective(`auctions`).getParticipants()
    function next() {
        if (!currentAuctions[0]) return;
        let current = currentAuctions[0]
        let currentScore = world.scoreboard.getScore(world.scoreboard.getObjective(`auctions`), currentAuctions[0])
        if (currentScore <= 0) {
            currentAuctions.splice(0, 1)
            next();
        }
        let change = world.scoreboard.setScore(world.scoreboard.getObjective(`auctions`), currentAuctions[0], currentScore - 1)
        console.warn(change)
        currentAuctions.splice(0, 1)
    }
    next()
}, 20 * 3)```
hearty surge
#

Any error?

stiff merlin
#

no

#

its returning true

hearty surge
#

How many player/score holder on auctions objectives?

stiff merlin
#

like how many participants?

hearty surge
#

Yes

stiff merlin
#

1

hearty surge
#

Hmm, I didn't see any error there

stiff merlin
#

im trying to a make a lag free clock that counts down in minutes (3 seconds for testing)

#

it should go in a chain order but that isnt working

#

its just looping the first entry

#

wait

#

nvm i fixed the loop issue

#

but the score is still not going down

hearty surge
#

Also, there's so many unused variable and useful code

stiff merlin
#

?

#

i removed current

#

system.runInterval(() => {
    let currentAuctions = world.scoreboard.getObjective(`auctions`).getParticipants()
    function next() {
        if (!currentAuctions[0]) return;
        let currentScore = world.scoreboard.getScore(world.scoreboard.getObjective(`auctions`), currentAuctions[0])
        if (currentScore <= 0) {
            currentAuctions.splice(0, 1)
            next();
        }

        let change = world.scoreboard.getObjective(`auctions`).setScore(currentAuctions[0], currentScore - 1)
        console.warn(currentAuctions[0].displayName)
        currentAuctions.splice(0, 1)
        next()
    }
    next()
}, 20 * 3)```
#

updated ^

hearty surge
#

Why you need function there? Like, it's only one participant

stiff merlin
#

its a auction house, so there will be more

#

i added 2 more to test and its working

hearty surge
#

Just use for loop

stiff merlin
#

right but should work too

#

my issue is just the score thing

#

do you think there is a fix?

hearty surge
#
import { world, system } from "@minecraft/server";

system.runInterval(async () => {
  let auctionObj = world.scoreboard.getObjective(`auctions`)

  for (const participant of auctionObj.getParticipants()) {
    await null;
    const currentScore = auctionObj.getScore(participants)
    if (currentScore <= 0) continue

    const isChange = auctionObj.setScore(participants, currentScore--)
    console.log(`Change ${participant.displayName}? ${isChange}`)
  }
}, 20 * 3)
```Try this
stiff merlin
#

still not removing score

#

should i just run a command instead?

hearty surge
#

What's your minecraft version?

stiff merlin
#

1.20

hearty surge
#

I've change the code, did it log Change <something>? true?

stiff merlin
#

yes

#

sorry for delay

hearty surge
#

And it's not changing?

stiff merlin
#

no

hearty surge
#

I guess try restart Minecraft

stiff merlin
#

alright

hearty surge
#

If it's still not working, then use runCommand

stiff merlin
#

Ok

#

ye runCommand is working

hearty surge
#

Kinda strange setScore is not working

stiff merlin
#

right

stiff merlin
#

@hearty surge im having another issue with the items

#

im trying to a player the item and its saying this

hearty surge
#

Show your code

stiff merlin
hearty surge
#

Please full code

stiff merlin
#

itemData is just a scoredboard name that is parsed into a object, the scoreboard info is

#

the data is the {}

#

like you said, it should act the same

hearty surge
#

Show your full code

stiff merlin
#
import { config } from "../../config"
import { runCommand } from "../../lib/functions/runCommand";

system.runInterval(() => {
    let finished = []

    world.scoreboard.getObjective(`auctions`).getParticipants().forEach(p => {
        if (world.scoreboard.getScore(world.scoreboard.getObjective(`auctions`), p) == 0) finished.push(JSON.parse(p.displayName.replaceAll(`*`, '\"')))
    })

    function next() {
        if (!finished[0]) return;

        let info = finished[0]

        let owner = world.getAllPlayers().find(plr => (plr.nameTag == info.owner))

        console.warn(info.bidding)

        if (info.bidding == false) {
            if (owner) {
                world.sendMessage(`test`)
                owner.getComponent(`inventory`).container.addItem(info.itemData)
                owner.sendMessage(`${config.serverMessage} §cYour auction was never purchased by a player! Your items have been returned back to you!`)
                runCommand(`scoreboard players reset "${JSON.stringify(info).replaceAll(`\"`, '*')}" auctions`)
            }
        }

        // if ()


    }

    next()

}, 20 * 3)```
hearty surge
#

Your item data is just {}

stiff merlin
hearty surge
#

That's why it send error

stiff merlin
#

its a the clone of the item

hearty surge
#

And you store it as string, which is delete all the data

stiff merlin
#

do you know a work around?

hearty surge
#

Don't save it on participant name

#

Save it on array

stiff merlin
#

how would i store that array without dleteing the data?

hearty surge
#

Store it inside variable

stiff merlin
#

i store my data in participants so if the world or server restarts or crashes it wont restart all the data

#

would that not restart that?

hearty surge
#

It's will restart that

#

That's the cons

stiff merlin
#

so your saying that it is not possiable as of right now to store item data in a string?

hearty surge
#

It's not and always not possible