#Json UI Variables

1 messages · Page 1 of 1 (latest)

frail karma
#

I'm looking for a good way to pass variables in to my json ui screen. So basically i want to create a system where i can do

    player.onScreenDisplay.setActionBar(
      `var1:21,var2:20,var3:10,var4:20`
    );

Then on my json ui, I will be able to grab those values. how can i do this?

fair sunBOT
#
Thanks for asking your question!

Once you have finished, please close your thread.

frail karma
#

At the moment im doing it like

"variables": [
      {
        "requires": "(not(($actionbar_text - 'var1:1') = $actionbar_text))",
        "$var1": 1
      },
      {
        "requires": "(not(($actionbar_text - 'var1:2') = $actionbar_text))",
        "$var1": 2
      },
      {
        "requires": "(not(($actionbar_text - 'var1:3') = $actionbar_text))",
        "$var1": 3
      },
      {
        "requires": "(not(($actionbar_text - 'var1:4') = $actionbar_text))",
        "$var1": 4
      }, etc...
]
#

its very inefficient and there must be a better way to do it

exotic iris
#

@frail karma If you strip away the alphabetical characters from a string, it will automatically convert the numerical string to a number. So you can pass in var1:# and strip away the var1: part, and # will automatically be converted to an integer. That way you can do it in one operation rather than a million requires sections

frail karma
exotic iris
exotic iris
#

#old-json-ui message

#

you can use that method to get a variables from the text you pass in

#

Do keep in mind if you use actionbar, you need to make a copy of $actionbar_text and modify that variable, as trying to modify the vanilla variable will result in errors since last few updates

frail karma
#

var1:21,var2:20,var3:10,var4:20,var5:"sdsdsd"

#

does that work

exotic iris
#

yes

frail karma
exotic iris
frail karma
#

how do i use this var_0 in text

#

like i want to create a label

#

how do i set the text to this var

merry jacinth
#

how is that working i dont get it

frail karma
merry jacinth
#

no? damn

#

by logic too i cant get it

frail karma
#

So with this you can use printf functions

#

When you multiply a formatting sentax by a string it will parse that string and return what you want

#

@merry jacinth

merry jacinth
#

oh yeah

frail karma
merry jacinth
#

🤔

frail karma
#

@exotic iris
Why am i able to do

    "$var_1": "((%.7s * $actionbar_raw_text))",
    "$var_2": "($var_1 - 'var1:')",
#

but i cant do

"$var_1": "((%.7s * $actionbar_raw_text) - 'var1:')",```
#

@vocal idol ^

frail karma
#

Key: _ Represents Space

"$actionbar_raw_text": "$actionbar_text", // ex: §z20 §z10 §z100§z34 
"$var_1_raw": "(%.6s * $actionbar_raw_text)", //§z20_
"$var_2_raw": "(%.6s * ($actionbar_raw_text - $var_1_raw))", //§z10_
"$var_3_raw": "(%.6s * ($actionbar_raw_text - $var_1_raw - $var_2_raw))", //§z100
"$var_4_raw": "(%.6s * ($actionbar_raw_text - $var_1_raw - $var_2_raw - $var_3_raw))", //§z34_
#

@exotic iris @vocal idol i made a system that actually works!

frail karma
#

@vocal idol Fixed your system this is how it should actually be done!

"(('%.' + $var_size + 's') * ($actionbar_raw_text - (('%.' + ($var_size * $var_index) + 's') * $actionbar_raw_text)))"
frail karma
#
  "variable_parser": {
    "$var_index": 0,
    "$var": "(('%.' + $var_size + 's') * ($actionbar_raw_text - (('%.' + ($var_size * $var_index) + 's') * $actionbar_raw_text)))"
  },```

And can be used by doing
```json
{
"[email protected]_parser": {
  "type": "label",
  "$var_index": 0, // Change to desired index for `$var`
  "font_type": "default",
  "text_alignment": "left",
  "line_padding": 2,
  "color": "white",
  "text": "$var",
  "font_scale_factor": 0.7,
  "size": ["85%", "default"],
  "offset": ["28%", "-14%"]
  }
}```
exotic iris
#

glad ya got it workin!