Using variables to trade in 10 items for 1

Is it possible to set up an event where a player hands in 10 of one item in return for 1 item? The answer is yes but I'd like to go further with an input.

So in my example, if the player has 10 fish they can trade for 1 sushi. But I'd like the player to be able to input a number like 20, 30, etc and get x in return depending on the input.

Course, I could always just make a branch to just check if 20, 30 etc was input but wondered if there was a more convenient way to do this with variables?

Thanks for reading.
You can simply use the Input Number... event command, where you can even specify the amount of digits the player can input. For example, 3 digits allows for any number from 0 to 999.

After that, you can easily calculate the amount of sushi to give the player by dividing the amount of fish by 10. To figure out how much fish to remove, it's as simple as multiplying the amount of sushi by 10.

This works because RPG Maker automatically rounds numbers down, so even if you have 23 fish, you'd get 2 sushi as a result, and 2 sushi times 10 is 20 fish. Remove 20 fish, and the player is left with 3 fish and 2 sushi.

Of course, this works for any conversion rate you can think of, not just 10. If you want to convert 3 lemons into 1 lemonade, you'd divide the amount of lemons by 3 to calculate the amount of lemonade to give, then you'd multiply the amount of lemonade by 3 to calculate the amount of lemons to remove.

23 lemons divided by 3 gives you 7 lemonade, and 7 lemonade times 2 results in 21 lemons to remove from the player's inventory. This leaves the player with 2 lemons and 7 lemonade.
I thought I understood what you were asking so I was experimenting with this. I got it to work, but were you asking if you could do this without ANY conditional branch?

As @Nolonar suggested above, I used the Input Number option. But then I used a Conditional Branch with a script to only allow the player to give 10, 20, or 30 fish at a time. If they tried to give something other than 10, 20, or 30, they would be told that wasn't a number that could be accepted.

This is the script I used:

$gameVariables.value(108) === 10 || $gameVariables.value(108) === 20 || $gameVariables.value(108) === 30

I wanted to make sure the player didn't give more than an increment of 10. But now that I think of it, you could only take the appropriate amount of fish based on the number of Sushi given and then you wouldn't need the Conditional Branch, I guess. So they could input 15, but you only give them 1 sushi and only remove 10 fish from their inventory.

And I multiplied the Input Number Variable by .1 to get the amount of Sushi to return.

EDIT: I tried what @Nolonar suggested above and it works great with a Conditional Branch. But when I was playing around with that, I realized that you would still probably need several Conditional Branches to deal with what happens if the player tries to give less than 10 or more than they actually have.
I just realized it might make more sense to ask the player how many sushi they want, rather than ask them how much fish they'd like to give.

By asking for fish, you'd need a relatively complex check to only allow for multiples of 10 as input. By asking for sushi instead, you could allow virtually any input, and would only need to check if the player has enough fish for the exchange.

The math involved is still the same: sushi * 10 tells you how much fish to deduce, and fish / 10 tells you how many sushi the player can receive from the fish they have in inventory. That way you can tell the player in advance that they only have enough fish for 3 sushi.
Thanks everyone!
$gameVariables.value(108) === 10 || $gameVariables.value(108) === 20 || $gameVariables.value(108) === 30

As a small JavaScript tip: you can use the % operator to get a remainder from division, which can be used to tell if a number is divisible by something or not. So instead of that condition you could do $gameVariables.value(108) % 10 === 0 - this would check if the remainder from dividing the variable by 10 is 0 (i.e. if the variable is divisible by 10).
As a small JavaScript tip: you can use the % operator to get a remainder from division, which can be used to tell if a number is divisible by something or not. So instead of that condition you could do $gameVariables.value(108) % 10 === 0 - this would check if the remainder from dividing the variable by 10 is 0 (i.e. if the variable is divisible by 10).
Wow, thanks for teaching me something new! I just modified my testing event and it works perfectly!

Thanks again!

Original thread: https://forums.rpgmakerweb.com/threads/using-variables-to-trade-in-10-items-for-1.153871/