TransWikia.com

Is there a way to put conditionals in functions?

Arqade Asked on December 31, 2020

Is there a way to make something conditional in a function? For example

setblock 5 10 5 air
tellraw @a {"rawtext":[{"text":"Placed!"}]} # <--- Make this command conditional (only runs if the setblock worked)
give @p diamond_helmet # <-- this runs anyway

I know how to do certain things conditionally such as running a command if a creeper is there:

execute @e[type=creeper,c=1] ~~~ execute @p ~~~ say Hi!

but for things other than single entity detection I don’t know how to approach this.

One Answer

This is a bit of a workaround, but it does the job:

setblock 5 10 5 air
execute @p 5 10 5 detect ~ ~ ~ air -1 tellraw @a {"rawtext":[{"text":"Placed!"}]}
give @p diamond_helmet

-1 is the Block ID. If set to -1 it will work with any Block ID. The execute command basically detects if what the previous setblock command was done.

Answered by radwl on December 31, 2020

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