#[RESOLVED] The texture doesn't get correctly binded

1 messages · Page 1 of 1 (latest)

fallen knoll
#

I want to change the texture of the control based on the title of the villager, however this doesn't work. I tried to bind the same binding to a text label, and it turns out it still prints the the title text that the vanilla UI shows, not the texture path I instructed to use.

  "villager_sprite":{
    "type":"image",
    "anchor_from":"bottom_left",
    "anchor_to":"bottom_left",
    "size": [38,39],
    "offset": [-2,7],
    "bindings":[
      {
        "binding_name": "('textures/ui/trading/professions/' + (%12s * #name_label))",
        "binding_name_override": "#texture"
      }
    ]
  },
sharp thicket
#

Just use the view binding

fallen knoll
# sharp thicket Just use the view binding

This way the control becomes invisible unless I reference a texture.
I structured the code this way

  "villager_sprite":{
    "type":"image",
    "anchor_from":"bottom_left",
    //"texture": "textures/ui/trading/professions/§c§0§7§f",
    "anchor_to":"bottom_left",
    "size": [38,39],
    "offset": [-2,7],
    "layer": 33,
    "bindings":[
      {
        "binding_type":"view",
        "source_control_name": "villager_name_label",
        "source_property_name": "('textures/ui/trading/professions/' + (%12s * #text))",
        "target_property_name": "#texture"
      }
    ]
  }```
#

I even tried replacing #text with #name_label

fallen knoll
#

If needed, here there is an example of my lang file:

entity.villager.armor=§c§0§7§fCorazzaio
entity.villager.butcher=§c§c§4§fMacellaio
entity.villager.cartographer=§c§6§e§fCartografo
entity.villager.cleric=§c§d§5§fChierico
entity.villager.farmer=§c§6§2§fAgricoltore
entity.villager.fisherman=§c§7§6§fPescatore
entity.villager.fletcher=§c§7§4§fArcaio
entity.villager.leather=§c§b§a§fConciatore
entity.villager.librarian=§c§e§f§fBibliotecario
entity.villager.shepherd=§c§7§f§fPastore
entity.villager.tool=§c§c§d§fFabbro d'attrezzi
entity.villager.weapon=§c§b§9§fArmaiolo
entity.villager.mason=§c§0§8§fMuratore```
sharp thicket
fallen knoll
#

I didn't even need to use the view binding, I could stick with the global one. I just needed to correct %12s into %.12s

#

Is it possible though to load a backup texture if it can't find one, for example, if the villager is renamed. The logic would be built around this I think

{
        "binding_name": "('textures/ui/trading/professions/' + (%.12s * #name_label))",
        "binding_name_override": "#test_text"
      }```
sharp thicket
#

I don't think there's a way to know if it was able to find the texture or not

fallen knoll
#

Oops ignore the #test_text

sharp thicket
fallen knoll
#

"binding_name": "((#name_label - '§f') = #name_label)",
I meant if this operation returns false

sharp thicket
#

I think you can

fallen knoll
#

I might have an idea

#

nvm I'll listen to you first

sharp thicket
#

First set the value in some binding e.g- #val

Then ('textures/ui/...' + ('%.' + (12*#val) + 's') * #name_label + ('%.' + (6*(1-#val)) + 's') * 'backup')

#

This should work ig

#

And do this inside a view binding otherwise it won't work

fallen knoll
sharp thicket
#

No. It might work inside a view binding but I'm not sure

#

Give it a try, you'll know yourself

fallen knoll
#

Thx. It is based on a logic for a code you suggested me a while back

#

IT WORKSSSS

sharp thicket
fallen knoll
#

Of course the texture is a placeholder

#

Nvm it doesn't

#

The true part works, but not the false part

sharp thicket
#

You're doing it inside binding_name?

fallen knoll
#

The operation to return the boolean is done inside binding name. The one for getting the true part is done inside the property bag

fallen knoll
#

What is #val?

sharp thicket
fallen knoll
sharp thicket
#

#val is the result of this expression
"binding_name": "((#name_label - '§f') = #name_label)",

fallen knoll
sharp thicket
#

Yeah

fallen knoll
#

Does this make sense? I don't think so
Do I trust you? Of course

sharp thicket
#

true will be treated as 1 and false will be treated as 0

fallen knoll
#

Oh I though that it returned true and false

#

This makes more sense

#

Ok I think I'm starting to understanding it, but wouldn't it be possible to simplify ('%.' + (6*(1-#val)) + 's') * 'backup') into (1-#val) * backup. Or is it not possible to multiply strings here?

sharp thicket
#

Nope

fallen knoll
#

I still can't understand what I did wrong
```json
"bindings":[
{
"binding_name": "#name_label"
},
{
"binding_name": "#((#name_label - '§f') = #name_label)",
"binding_name_override": "#val"
},
{
"binding_type":"view",
"source_control_name": "villager_sprite",
"source_property_name": "('textures/ui/trading/professions' + ('%.' + (12*#val) + 's') * #name_label + ('%.' + (6*(1-#val)) + 's') * 'backup')",
"target_property_name": "#texture"
}

sharp thicket
#

Why are you using a source control name and your second binding object has an extra # at front

fallen knoll
#

I then deleted source_control_name mb, as for the extra #, where do you see that?

#

Oh...

#

I'll give you the reason for the extra #: because I'm a moron

#

I honestly didn't see that

sharp thicket
#

It happens :)

#

Show it in a label to see if it's working properly

fallen knoll
#

Yeah that's I was doing

#

OK I'M THIS CLOSE TO ALWAYS REACTING 🍊 INSIDE OF THE #1019665690233405500 threads (I'll do that anyways)

sharp thicket
#

Where did .6 come from

fallen knoll
#

Idk

#

I then tried to remove a pair of brackets from ('%.' + (6*(1-#val)) + 's') * 'backup'), so it became ('%.' + 6*(1-#val)) + 's' * 'backup')

#

and the .6 became backup

#

but despite the correct path being displayed, the texture still doesn't get referenced

sharp thicket
#

Don't remove the brackets those are necessary

fallen knoll
#

Guess I'm back with the .6 then

sharp thicket
#

Can you send the bindings again
The updated one

fallen knoll
#
    "bindings":[
      {
        "binding_name": "((#name_label - '§f') = #name_label)",
        "binding_name_override": "#val"
      },
      {
        "binding_type":"view",
        "source_property_name": "('textures/ui/trading/professions/' + ('%.' + (12*#val) + 's') * #name_label + ('%.' + (6*(1 - #val) + 's')) * 'backup')",
        "target_property_name": "#test_text"
      }
#

I honestly don't even know how you're able to be ok despite dealing with weird problems of people like me in this server

#

But at least you're an expert, as I saw from your DungeonUI

sharp thicket
#

An attempt to make a UI haha

fallen knoll
#

You're quite humble to call it an attempt

fallen knoll
#

I don't even know or even want to know why you built that...

fallen knoll
sharp thicket
#
    "bindings":[
      {
        "binding_name": "#name_label",
      },
      {
        "binding_type":"view",
        "source_property_name": "((#name_label - '§f') = #name_label)",
        "target_property_name": "#val"
      },
      {
        "binding_type":"view",
        "source_property_name": "('textures/ui/trading/professions/' + ('%.' + (12 * #val) + 's') * #name_label + ('%.' + (6 * (1 - #val)) + 's') * 'backup')",
        "target_property_name": "#test_text"
      }
    ]
#

Try this

fallen knoll
#

The only change is converting the second object into a view binding, right?

sharp thicket
#

Wait there are some invalid brackets that might be the issue

#

Try the updated one

fallen knoll
#

so... the backup texture gets loaded where it shouldn't and the renamed villagers (the ones who do need the backup texture) don't have any texture

#

marvelous

sharp thicket
#

So it's opposite?

fallen knoll
#

I guess so

sharp thicket
#

I think I misunderstood you a bit
When this (#name_label - '§f') = #name_label is true should the backup be visible or the actual texture

#

This will be true when the name doesn't contain §f

fallen knoll
#

Oh you're right I didn't notice

#

I think I'm near the solution now, I'll fix it later. Thank you so much again

sharp thicket
#

Hope it works 🍀
The logic seems okay but it doesn't work as expected :(

fallen knoll
#

Ok theoretically the part of the renamed villager, but not the other part (the one with the 12)
('textures/ui/trading/professions/' + (('%.' + (12 * (1 - #val)) + 's') * #name_label) + (('%.' + (6 * #val) + 's') * 'backup')))

#

I'm pretty sure it's a bracket thing

#

Finally fixed it. I just needed to remove a pair of brackets (the one before the 12 and one after the first #val). Thank you again