1

How do you make a command block if/else?

luigi_vampa's Avatar luigi_vampa7/17/19 9:41 am
1 emeralds 10.2k 5
7/18/2019 9:29 am
HoboMaggot's Avatar HoboMaggot
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.
Posted by luigi_vampa's Avatar
luigi_vampa
Level 52 : Grandmaster Dragonborn
176

Create an account or sign in to comment.

5

1
07/18/2019 1:10 am
Level 52 : Grandmaster Blob
HoboMaggot
HoboMaggot's Avatar
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 ...
1
07/18/2019 5:42 amhistory
Level 52 : Grandmaster Dragonborn
luigi_vampa
luigi_vampa's Avatar
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++;
1
07/18/2019 9:29 amhistory
Level 52 : Grandmaster Blob
HoboMaggot
HoboMaggot's Avatar
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?)
1
07/17/2019 10:36 pm
Level 52 : Grandmaster Blob
HoboMaggot
HoboMaggot's Avatar
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.
1
07/17/2019 11:11 pm
Level 52 : Grandmaster Dragonborn
luigi_vampa
luigi_vampa's Avatar
Hello. The value of TL_1 is set inside the two functions that are called.
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome