Aedif / TokenVariants

GNU General Public License v3.0
17 stars 12 forks source link

Dynamic text in info box example? #120

Closed kevinb0 closed 10 months ago

kevinb0 commented 11 months ago

Hey there,

As a user, I'd like to be able to construct strings dynamically, and use them in the text field.

I was experimenting with this, and I thought it'd be cool to use it to get an "at a glance" popup of what a unit was carrying on their inventory, however, there doesn't appear to be a way dynamically construct a text array and display that - I think it'd be quite powerful to be able to have an "on open" script run, and then do stuff with the data that comes out of it.

As an example, here's what I'm trying to do - (this is for the Twilight 2K system, but hopefully the intent can be found)

let text = [];
actor.items.forEach((i) => {
    if ((i.type === 'item' || i.type === 'weapon' || i.type === 'armor' || i.type === 'gear' || i.type  === 'grenade') && i.system.equipped) {
        text+=`"${i.name}" \n`
    }
});

console.log(text)

Ideally I'd like to display the output text somewhere, particularly in the text field, although with the current implementation it doesn't seem to be possible.

Aedif commented 11 months ago

As of release 4.49.0 you should be able to enter code into the text field and have it be evaluated:


let text = '';
token.actor.items.forEach((i) => {
  if (
    (i.type === 'item' ||
      i.type === 'weapon' ||
      i.type === 'armor' ||
      i.type === 'gear' ||
      i.type === 'grenade') &&
    i.system.equipped
  ) {
    text += `${i.name} \n`;
  }
});
text;

This was actually already possible for other fields. The support was just extended to this one as well.