#Reading scoreboard objectives in JSON UI
1 messages · Page 1 of 1 (latest)
wouldnt you use scripts for this?
function getScore(target, objective, useZero = false) {
try {
const oB = world.scoreboard.getObjective(objective);
if (typeof target == 'string') {
return oB.getScore(oB.getParticipants().find(pT => pT.displayName == target));
}
return oB.getScore(target.scoreboardIdentity);
} catch {
return useZero ? 0 : NaN;
}
}
```just paste this in ur scripts file, then in ur string just do ${getScore(player, "objectiveName")}
Thanks! (I'm like really new to JSON UI)
u do know how scipts work tho right
yup, js didnt know that they connected that easily
Yea but I thought you needed to use binding
oh no lmao
then just add it in their and ur good to go
okay and u script right
mhm
okay go to the file this code is in
nono the profile
or server_form
not json ui
same exact file
oh lord okay
(I got cody to comment everything)
rq make a config.js file
this is like a utility file for stuff that might need to be used in many fles
scripts
then paste this code in their
export function getScore(target, objective, useZero = false) {
try {
const oB = world.scoreboard.getObjective(objective);
if (typeof target == 'string') {
return oB.getScore(oB.getParticipants().find(pT => pT.displayName == target));
}
return oB.getScore(target.scoreboardIdentity);
} catch {
return useZero ? 0 : NaN;
}
}
cooked
?
oh yeh remove the js
got it
import { world } from "@minecraft/server";
add that to the top of taht file
because we need world for world.scoreboard
should I import config.js from my main.js?
nono okay so because we are exporting the fucntion getScore
we now import that into gui.js
so we can get the getScore function
ah gotcha (I started Script Api on may 10th)
this is what I need rn
reason i made u make a config file is so u dont have to have the getScore function in multiple files
just cleaner code
Oh so should I delete the old code you sent in main.js?
so importing it into ur gui.js will look like import { getScore } from "filepathing"
yeah we dont need that in there
its already in config so we can import it into afile when we need to use it
Got it!
so have u imported it into your gui.js?
Yup!
make sure the filepathing is correct too
okay show the code for the profile again
imports should also be at the top of ur file
i think that is just cant tell
can u vc? this would be alot easier
Alr
?
I meant to reply to vc
{
"deaths_panel": {
"type": "panel",
"size": ["30%", "100%"],
"anchor_from": "center",
"anchor_to": "center",
"controls": [
{
"deaths_icon": {
"type": "image",
"size": [24, 24],
"offset": [0, -15],
"texture": "textures/ui/icon_recipe_nature",
"layer": 2
}
},
{
"deaths_label": {
"type": "label",
"text": "Deaths",
"color": [1.0, 0.3, 0.3],
"offset": [0, 5],
"layer": 2
}
},
{
"deaths_value": {
"type": "label",
"text": "",
"color": [1.0, 0.3, 0.3],
"offset": [0, 25],
"layer": 2
}
}
]
}
},
Yo! Js wanted to tell you (with your help) I got it to have multiple bodys!
w
Mind if I use the code to get the score?
Like just to get the players score from that specific scoreboard
