#slider

1 messages · Page 1 of 1 (latest)

spiral kelp
#
function komur(player) {
   
    
    const modal = new ModalFormData();
    modal.title(`§eKömür Sat`);
    modal.slider("test", 1, 2, 3);
    
    modal.show(player).then(result => {
        if (result.formValues[1] !== "") {


   }     
    })
}
#

I want to change the slider option according to how many are coal in the player's inventory

zinc grail
#

Use [0]

#

Since it's at the start of an array index

#

Also, just looping the inventory

#
function itemAmount(itemId) {
  let amount = 0;
  const container = player.getComponent("inventory").container;

  for (let i = 0; i < container.size; i++) {
    const item = container.getItem(i)
    if (item?.typeId !== itemId) continue;
    amount += item.amount
  }

  return amount;
}
spiral kelp
scenic onyx
scenic onyx
#

and not let the rest of the code run

zinc grail
#

Wait, I accidentally typed return instead of continue

hallow ingot
#

or u can just do const [slider] = result.formValues

#

for each new formValue, u add a new property to the array

zinc grail
scenic onyx
#
function komur(player) {
    const modal = new ModalFormData();
    modal.title( `§eKömür Sat` );
    modal.slider( "test", 1, getItemAmount( player, "minecraft:coal" ), 1 );
    modal.show( player ).then(
        (response) => {
            const [ coal ] = response.formValues;
            console.warn( coal );
        },
    );
};

function getItemAmount(player, itemId) {
    let amount = 0;
    const inventory = player.getComponent( "minecraft:inventory" ).container;
    for (let i = 0; i < inventory.size; i++) {
        const item = inventory.getItem(i);
        if (item?.typeId == itemId) amount += item.amount;
    };

    return amount;
};
zinc grail
scenic onyx
#

where?

hallow ingot
#

at the very end

#

to close the slider

scenic onyx
#

i can’t see stuff better on mobile lol

zinc grail
#
modal.slider( "test", 1, getItemAmount( player, "minecraft:coal" ), 1 );
hallow ingot
#

or whatever he did

scenic onyx
#

fixed!

crystal sonnetBOT
#
Debug Result

There is an error in this [code](#1134467833896648704 message):

<repl>.js:7:19 - error TS2488: Type '(string | number | boolean)[] | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.

7             const [ coal ] = response.formValues;
                    ~~~~~~~~

scenic onyx
#

i hate strict mode

scenic onyx
#

yay!