How to a shop where you can select items from the shelf and have to pay for it at counter

Im making a supermarket where if you leave with the item or if you can't pay you will die so you can choose a few items from shelfs than pay at counter you can't return items so can someone tell me how i can make a shop where you can select items from the shelf and have to pay for it at counter
Make it so when you select an item from the shelf, it turns on a switch that represents that item. Then when they go to the checkout counter, make a conditional statement that checks if that specific switch is on, and if so, it hands them the item, deducts the gold, and turns the switch back off.
Switches and variables are your friends.
But what if they buy few items at the same time?
Make it so when you select an item from the shelf, it turns on a switch that represents that item. Then when they go to the checkout counter, make a conditional statement that checks if that specific switch is on, and if so, it hands them the item, deducts the gold, and turns the switch back off
But what if they buy few items at the same time?
Use a switch for each possible item, then have your shopkeeper event run a conditional branch for each one in sequence.
People are talking about switches, but those only work if you want to buy only 1 of each item. If you want to buy more than 1 of each item (e.g. 3 apples and 7 bananas), use variables instead.

If the player interacts with the shelf, show a choice where they can choose an item to take. Don't forget a "Cancel" choice just in case the item they want isn't in the shelf they're interacting with or they simply don't wish to take anything.

Once the player chose an item, ask them how many they want, and save the result in a variable (each item needs its own variable).

When they try to leave, check if at least one of the variables is greater than zero.

When the player interacts with the shopkeeper, use those variables to calculate the total price. For example, if an apple costs 80 and a banana costs 100, and the player took 3 apples and 7 bananas, the player will need to pay 3 * 80 + 7 * 100 = 940 in total. To calculate this, use 2 additional variables. The first one is used to calculate the price of 1 item (e.g. 3 * 80), which you then add to the second one. The total price would be stored in that second variable.

Check if the player can afford that. If not, tell them they can't afford it and they should put some of those items back. If the player can afford it, ask them if they want to pay. If yes, give them the items using the variables, set the variables to 0, and deduct the price from the player's wallet.

Also don't forget to give the player an easy way to empty their shopping basket. They won't like it, if they have to return to the shelves to return 7 bananas, then die because they forgot they were still carrying 3 apples.

And if I were you, I'd display the picture of a shopping basket while any of the variables are non-zero. You'll save a lot of players' lives that way.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-a-shop-where-you-can-select-items-from-the-shelf-and-have-to-pay-for-it-at-counter.143105/