Is there a way I can store variables in my Minecraft world?

I’m trying to make bank accounts for players in a Minecraft world. Is there a feature in Minecraft commands that would enable me to do this using variables? If so, which commands would allow me to utilise this, or if not, what would be my best option?


Solution 1:

Scoreboards are the tool you're looking for. All of the scoreboard commands are explained in the wiki link, but since it may be overwhelming, I'll try to present it in a more digestible format tailored to your specific needs below.

For making bank accounts, you could make a new objective for the amount of money a player has, which could be called "money". You will want this objective to be of the dummy criteria (which is what the dummy suffix below means) because it isn't based on a preexisting Minecraft value, and you won't want players to arbitrarily control their own money.

scoreboard objectives add money dummy

Then to begin tracking a player's money:

scoreboard players add playerName money

Or better yet, use target selectors for generic player inclusion:

scoreboard players add @p money

There are many different commands to modify and evaluate a player's money. set, add, remove, and test are probably vital. They can be used as follows:

Set a player's balance to 0:

scoreboard players set playerName money 0

Add 10 to a player's balance:

scoreboard players add playerName money 10

Remove 10 from player's balance:

scoreboard players remove playerName money 10

Test if a player's balance is greater than or equal to 100:

scoreboard players test playerName money 100

Here are some other commands you can use.

In order to have a well-functioning and automatically managed bank, you'll also want to investigate command blocks. Conditional command blocks are particularly vital. Target selectors will also be necessary (as opposed to the playerName I gave in my above examples), because you shouldn't be using player names if you want a scalable system.