1

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.

buildBattle.mcfunction

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

initialize.mcfunction

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?

0

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.

-1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.