In minecraft bedrock Im trying to execute a function if it has not yet been executed to initialize a build battle map. There is a command block with a button and the command it executes is "/function buildBattle". When I push the button the first time it should call the initialize function. If I push it again it should not.


#assume activeGame is not null for any user and is set to 0 somewhere else
execute @p[scores={activeGame=0}] ~ ~ ~ function initialize


scoreboard players set @a activeGame 1

My function logic is not exactly correct. If any player joins with an activeGame of 0 and pushes the button it will call the initialize function. Is there some other way to do this?

3 Answers 3


The correct way to do this is to use a global armor stand. That is, an armor stand that uses its scoreboards as variables.

In your world, create an armor stand with the name "global":

summon minecraft:armor_stand 0 255 0 {CustomName:'{"text":"global"}',NoAi:1b}

Now, you can store variables globally inside of this entity, like so:

scoreboard players set @e[type=armor_stand,name="global"] activeGame 1

Here's something really simple, just use a block that is somewhere close to the command block, like right next to it or a bit under it or something of the sort. Instead of having one command block, make it 2 (make them a chain and the second one conditional) and make the first command

testforblock 5 10 7 bedrock

Obviously replace 5 10 7 with the appropriate coordinates and then in the second command block that is conditional, chain, and always active:

function initialize

Then in the start of the function, add the line:

setblock 5 10 7 bedrock

Again, replace 5 10 7 with what you put before, and you're done! If you ever want to enable it again you can just replace the block at 5 10 7 or wherever to anything except bedrock (like air).

These systems are really handy because not only can you store binary information (true/false etc.) you can store so many like 4 different options, 10 different, etc.. It's also really easy to reset manually without having to punch in commands to the chat every time, and also shows you immediately why something may be misbehaving.


Mabe you could have it put a tag on any joining players once it has started and remove it at the end.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .