#Help
1 messages · Page 1 of 1 (latest)
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
how would i do so?
Reconstruct the item data into new object
the entire thing?
Yes
damn
so i would have to recreate the functions to? so like getComponent?
@hearty surge
I don't think you can recreate the function too
console.warn(JSON.stringify(deepCopy(item)))
Np
Don't use deepCopy
addItem need real/native Item class, not cloned Item class as object
Use deepCopy when you want to console out the data, otherwise, just do normal
but would it work? its returning {} for the data
Mojang change how JSON.stringify works, by always returning {} every native class, even tho they have all the data
so visually it shows {} but it has the data in it correct?
That's why you always got {}, but the code still run perfectly
Yes
They purposely hide it
why?
Idk
@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)```
Any error?
How many player/score holder on auctions objectives?
like how many participants?
Yes
1
Hmm, I didn't see any error there
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
Also, there's so many unused variable and useful code
?
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 ^
Why you need function there? Like, it's only one participant
Just use for loop
right but should work too
my issue is just the score thing
do you think there is a fix?
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
What's your minecraft version?
1.20
I've change the code, did it log Change <something>? true?
And it's not changing?
no
I guess try restart Minecraft
alright
If it's still not working, then use runCommand
Kinda strange setScore is not working
right
@hearty surge im having another issue with the items
im trying to a player the item and its saying this
Show your code
Please full code
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
Show your full code
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)```
Your item data is just {}
That's why it send error
its a the clone of the item
And you store it as string, which is delete all the data
do you know a work around?
how would i store that array without dleteing the data?
Store it inside variable
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?
so your saying that it is not possiable as of right now to store item data in a string?
It's not and always not possible