TransWikia.com

In Minecraft bedrock can I create a function block that only executes another function once?

Arqade Asked on July 7, 2021

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?

2 Answers

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

Answered by slimeccrafter on July 7, 2021

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.

Answered by Penguin on July 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP