#how can i bind things to textures? [Resolved]

1 messages · Page 1 of 1 (latest)

sly igloo
#
"variables": [
              {
                "requires": "((.4s * #title_text) = '§a§№')",
                "$formc": [
                  0,
                  1,
                  0
                ]
              },
              {
                "requires": "((.4s * #title_text) = '§b§№')",
                "$formc": [
                  0,
                  0,
                  1
                ]
              },
              {
                "requires": "((.4s * #title_text) = '§d§№')",
                "$formc": [
                  1,
                  0,
                  1
                ]
              }

i have a variable called $formc, and basically i am wanting it to change when the first four characters of my server form title text are the string i set.

it doesnt work for some reason, and i suppose its the expression

#

issue with binding/variable operations

frozen acorn
#

you cant operate bindings with variables

sly igloo
frozen acorn
#

you cant do "$var": "#bind"

#

but you can "#bind": "$var"

sly igloo
#

thats weird

frozen acorn
#

yea

sly igloo
frozen acorn
#
"$var": 1,
"property_bag": {
  "#bind": "$var"
}
sly igloo
#

this is confusing

sly igloo
frozen acorn
#

what are u doing with formc?

sly igloo
#

its for color property

#

i want to apply the property

#

so i did smt like that and made formc variable

frozen acorn
#
    "property_bag": {
        "#§a§№": [0, 1, 0, 1],
        "#§b§№": [0, 0, 1, 1],
        "#§d§№": [1, 0, 1, 1]
    },
    "bindings": [
        {"binding_name": "#title_text"},
        {
            "binding_type": "view",
            "source_property_name": "('#' + '%.8s' * #title_text)",
            "target_property_name": "#color"
        }
    ]
#

add this to your element

#

-# edited it, just change the .7s to .8s

sly igloo
#

ok

#

why %.8s tho

#

it doubles?

frozen acorn
#

short explain

sly igloo
#

ohh

frozen acorn
#

Great question! Let’s break it down carefully, because the number of bytes depends on the character encoding being used (most commonly ASCII or UTF‑8 today).


1. Character: a

  • In ASCII: a is U+0061 → 1 byte
  • In UTF‑8: Same as ASCII → 1 byte

2. Character: § (Section Sign)

  • Unicode code point: U+00A7
  • In ASCII: Not representable (ASCII only covers 0–127)
  • In UTF‑8: Encoded as 0xC2 0xA72 bytes

3. Character: (Numero Sign)

  • Unicode code point: U+2116
  • In ASCII: Not representable
  • In UTF‑8: Encoded as 0xE2 0x84 0x963 bytes

✅ Total in UTF‑8

  • a → 1 byte
  • § → 2 bytes
  • → 3 bytes

Total = 6 bytes


So, the string "a§№" uses 6 bytes in UTF‑8.

Would you like me to also show how these characters would be stored in UTF‑16 or other encodings (like ISO‑8859‑1)? That way you can compare how different systems handle them.

sly igloo
#

i see

#

i forgot about the byte stuff

frozen acorn
#

yup

sly igloo
#

it works now

#

thank you man

frozen acorn
#

yeah np

sly igloo
#

so property bag lets you create binds for values which can be used in binding operations?

frozen acorn
#

exactly

sly igloo
#

ah

#

what does variables have to do with it

#

i used this before to turn $actionbar_text into a bind

frozen acorn
#

yeah you can var -> bind using "#bind": "$var"

#

but you cant do bind -> var

#

like "$var": "#var"

#

you cant do that

#

I don't remember the reason, but it was something like the variables being parsed before the bindings.

sly igloo
#

how come it is seen done in the vanilla files?

#

or is that due to hardcoded

frozen acorn
#

oh nono

#

they are used just like templates ig

#

like this ```json
"$visibility_binding_name": "#is_creative_mode",
"bindings": [
{
"binding_name": "$visibility_binding_name",
"binding_name_override": "#visible"
}
]

#

so if i dont wanna change all, i can do "$visibility_binding_name": "#is_spectator_mode"

#

-# just an example ig

sly igloo
#

ah

frozen acorn
#

idk how to explain it

sly igloo
#

yeah it seems hard to explain considering you can do one thing and cant do the other yet they look the same

frozen acorn
#

basically, "$var": "#bind" is like change every '$var' to '#bind', not $var will take the value of #bind

sly igloo
#

btw why do you include 1 as the fourth array value in the colors

#

is it not rgb?

#

or can you use rgb and rgba

frozen acorn
#

rgb wont work if you use it with bindings

#

instead use rgba

#

but its not like if you put 0 the image will become transparent

#

instead color will have no effect

#

its more like a tint ig

sly igloo
#

ah

frozen acorn
#

for transparency use "alpha": 0 - 1, you can use floats

sly igloo
#

yeah ik, i love alphas

#

issue with binding/variable operations [Resolved]

sly igloo
#

@frozen acorn

"property_bag": {
                        "#§a§№": "textures/ui/default_c_button",
                        "#§b§№": "textures/ui/default_c_button_blue",
                        "#§d§№": "textures/ui/default_c_button_purple"
                        "#ftexture": ""
                    },
                    "$default_button_texture": "#ftexture",
                    "$bbindings": [
                        {
                            "binding_type": "collection_details",
                            "binding_collection_name": "form_buttons"
                        },
                        {
                            "binding_name": "#title_text"
                        },
                        {
                            "binding_type": "view",
                            "source_property_name": "('#' + '%.8s' * #title_text)",
                            "target_property_name": "#ftexture"
                        }
                    ],

this should work, no? i am trying to do the same thing but this time give button textures based off of text

frozen acorn
#

i guess you are ussing @common_buttons.light_text_button or something else?

sly igloo
#

perhaps its #form_button_texture

sly igloo
#

how can i bind things to textures?

upper meadow
#

i have same issue

sly igloo
upper meadow
sly igloo
#

"bindings": "$bbindings"

upper meadow
sly igloo
#

ok

upper meadow
sly igloo
upper meadow
sly igloo
#

ok thank you

#
"property_bag": {
                        "#§a§№": "default_c_button",
                        "#§b§№": "default_c_button_blue",
                        "#§d§№": "default_c_button_purple"
                    },
                    "$ftexture": "('textures/ui/' + #ftexture)",
                    "$default_button_texture": "$ftexture",
                    "bindings": [
                        {
                            "binding_type": "collection_details",
                            "binding_collection_name": "form_buttons"
                        },
                        {
                            "binding_name": "#title_text"
                        },
                        {
                            "binding_type": "view",
                            "source_property_name": "('#' + ('%.8s' * #title_text))",
                            "target_property_name": "#ftexture"
                        }
                    ]
#

so it should look something like this then?

pseudo plume
#

Variables can't use bindings

sly igloo
#

the code above is wrong then

pseudo plume
#
"property_bag": {
                        "#§a§№": "default_c_button",
                        "#§b§№": "default_c_button_blue",
                        "#§d§№": "default_c_button_purple"
                    },
                    
                    "$default_button_texture": "$ftexture",
                    "bindings": [
                        {
                            "binding_type": "collection_details",
                            "binding_collection_name": "form_buttons"
                        },
                        {
                            "binding_name": "#title_text"
                        },
                        {
                            "binding_type": "view",
                            "source_property_name": "('textures/ui/' + ('#' + ('%.8s' * #title_text)))",
                            "target_property_name": "#texture" // this will automatically change the texture, no need for "texture": "something"
                        }
                    ]
sly igloo
#

but i just want to change the default texture

#

does this not change the texture for every type, hover, pressed

pseudo plume
#

Well in that case you need to use the bindings separately for default_control, hover_control and pressed_control

sly igloo
#

ahhh

pseudo plume
#

The bindings have to be directly on the image

sly igloo
# pseudo plume ```json "property_bag": { "#§a§№": "default_c_button", ...
"default@$button_state_panel": {
"property_bag": {
                        "#§a§№": "default_c_button",
                        "#§b§№": "default_c_button_blue",
                        "#§d§№": "default_c_button_purple"
                    },
                    
                    "bindings": [
                        {
                            "binding_type": "collection_details",
                            "binding_collection_name": "form_buttons"
                        },
                        {
                            "binding_name": "#title_text"
                        },
                        {
                            "binding_type": "view",
                            "source_property_name": "('textures/ui/' + ('#' + ('%.8s' * #title_text)))",
                            "target_property_name": "#texture"
                        }
                    ]
}

would this work

#

and so on for other states

pseudo plume
#

I don't think so. It depends on your $button_type_panel. If it's the image then it should work. But if you're using the template buttons it probably won't work

sly igloo
#

i see

pseudo plume
#

If you're going to use textures using bindings it's better to use custom buttons using common.button
Instead of the template buttons

sly igloo
#

this is for a server form

#

so i will just use the image

#

actually you might be right nvm