1
How do you make a command block if/else?
I've got four command blocks in a row, the first two are part of a timer. One increments an armor stand entity (aa207361-0449-4786-9b8f-957a2bd41ee5) score by one every tick and the other resets it when it reaches 1200.
REPEAT
scoreboard players add aa207361-0449-4786-9b8f-957a2bd41ee5 Timer 1
CHAIN
execute if score aa207361-0449-4786-9b8f-957a2bd41ee5 Timer matches 1200 run scoreboard players set aa207361-0449-4786-9b8f-957a2bd41ee5 Timer 0
CHAIN/CONDITIONAL
execute if score aa207361-0449-4786-9b8f-957a2bd41ee5 TL_1 matches 0 run function ...
CHAIN
execute if block ~ ~ ~-1 minecraft:chain_command_block{SuccessCount:0} if score aa207361-0449-4786-9b8f-957a2bd41ee5 TL_1 matches 1 run function ...
The last two command blocks don't execute properly. I think the problem is related to the SuccessCount:0 firing every tick and not once only every 1200 ticks dependent on whether the value of TL_1 is 1 or 0.
How do I program the last two command blocks to act as an if/else that's tested once every 1200 clicks
Thanks.
REPEAT
scoreboard players add aa207361-0449-4786-9b8f-957a2bd41ee5 Timer 1
CHAIN
execute if score aa207361-0449-4786-9b8f-957a2bd41ee5 Timer matches 1200 run scoreboard players set aa207361-0449-4786-9b8f-957a2bd41ee5 Timer 0
CHAIN/CONDITIONAL
execute if score aa207361-0449-4786-9b8f-957a2bd41ee5 TL_1 matches 0 run function ...
CHAIN
execute if block ~ ~ ~-1 minecraft:chain_command_block{SuccessCount:0} if score aa207361-0449-4786-9b8f-957a2bd41ee5 TL_1 matches 1 run function ...
The last two command blocks don't execute properly. I think the problem is related to the SuccessCount:0 firing every tick and not once only every 1200 ticks dependent on whether the value of TL_1 is 1 or 0.
How do I program the last two command blocks to act as an if/else that's tested once every 1200 clicks
Thanks.
Create an account or sign in to comment.
5
1
If you want both of them to detect as soon as 1200 ticks go by, I'd use
/execute if score aa207361-0449-4786-9b8f-957a2bd41ee5[scores={Timer=1200}] TL_1 matches 0 run function ...
execute if block ~ ~ ~-1 minecraft:chain_command_block{SuccessCount:0} if score aa207361-0449-4786-9b8f-957a2bd41ee5[scores={Timer=1200}] TL_1 matches 1 run function ...
/execute if score aa207361-0449-4786-9b8f-957a2bd41ee5[scores={Timer=1200}] TL_1 matches 0 run function ...
execute if block ~ ~ ~-1 minecraft:chain_command_block{SuccessCount:0} if score aa207361-0449-4786-9b8f-957a2bd41ee5[scores={Timer=1200}] TL_1 matches 1 run function ...
1
Sorry, it's probably easier for me to explain in code.
This is what I'm trying to achieve;
if(Timer == 1200)
{
if(TL_1 == 0)
{
run function mechanics:traffic_lights/tl1_sqnc1;
}
else
{
run function mechanics:traffic_lights/tl1_sqnc2;
}
}
Timer++;
This is what I'm trying to achieve;
if(Timer == 1200)
{
if(TL_1 == 0)
{
run function mechanics:traffic_lights/tl1_sqnc1;
}
else
{
run function mechanics:traffic_lights/tl1_sqnc2;
}
}
Timer++;
1
I'm pretty sure both commands without the successcount are reliable enough to work.
If/else (elif in python etc) isn't really integrated in mc. only "/execute unless" which is kinda more of an else instead or to get if/ese, use execute if 2 or more times.
/execute if score aa207361-0449-4786-9b8f-957a2bd41ee5[scores={Timer=1199}] TL_1 matches 0
which will run 0's function and
/execute if score aa207361-0449-4786-9b8f-957a2bd41ee5[scores={Timer=1199}] TL_1 matches 1
which will run 1's function.
These alone (try to put it in individual repeating, active cmd blocks, if chain doesnt work) are supposed to work by themselves, because it satisfies/fails their own if statements individually.
Note I changed the timer to 1199, since timer resets are apparently funky.
If it fails can you elaborate on the errors your original commands generated (any output logs in cmd blocks?)
If/else (elif in python etc) isn't really integrated in mc. only "/execute unless" which is kinda more of an else instead or to get if/ese, use execute if 2 or more times.
/execute if score aa207361-0449-4786-9b8f-957a2bd41ee5[scores={Timer=1199}] TL_1 matches 0
which will run 0's function and
/execute if score aa207361-0449-4786-9b8f-957a2bd41ee5[scores={Timer=1199}] TL_1 matches 1
which will run 1's function.
These alone (try to put it in individual repeating, active cmd blocks, if chain doesnt work) are supposed to work by themselves, because it satisfies/fails their own if statements individually.
Note I changed the timer to 1199, since timer resets are apparently funky.
If it fails can you elaborate on the errors your original commands generated (any output logs in cmd blocks?)
1
lmao this is all confusing me.
How did TL_1 come by?
TL_1 isnt set so the last 2 commands dont know what score TL_1 is.
How did TL_1 come by?
TL_1 isnt set so the last 2 commands dont know what score TL_1 is.
1
Hello. The value of TL_1 is set inside the two functions that are called.