Forumskeyboard_arrow_right Help keyboard_arrow_right Java Edition

Create Forum Thread
1

How do you make a command block if/else?

1 emeralds5 replies62 views
created 07/17/2019 9:41 am by luigi_vampa
last reply 07/18/2019 9:29 am
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 avatar
luigi_vampa
Level 50 : Grandmaster Dragonborn
163

comment Login or register to post a reply.

5 replies

1
07/18/2019 1:10 am
Level 8 : Apprentice Modder
HoboMaggot
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 50 : Grandmaster Dragonborn
luigi_vampa
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 8 : Apprentice Modder
HoboMaggot
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 8 : Apprentice Modder
HoboMaggot
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 50 : Grandmaster Dragonborn
luigi_vampa
Hello. The value of TL_1 is set inside the two functions that are called.

Planet Minecraft

Browse

Site

© 2010 - 2019
planetminecraft.com

Welcome