In order to detect the value of any gamerule (both default and custom), CommandStats must be used, which will set the value of the gamerule as a score. Only the QueryResult
trigger will be provided with a return value when running /gamerule <name>
.
Prerequisites
Objective to hold the value.
/scoreboard objectives add Gamerules dummy
The target of CommandStats must be tracked in the objective in order to obtain the return value. In this case, a fake player named "$customGamerule" will be used to hold the value.
/scoreboard players set $customGamerule Gamerules 0
You can set the custom gamerule's value to any numerical value for detection. If you set it to "true" or "false", it will be interpreted as 1 and 0 respectively. If you set it to any other string, it will be 0.
/gamerule customGamerule 0
/gamerule customGamerule 1
/gamerule customGamerule 100
/gamerule customGamerule true
Detection

Stand on top of the command block and run the following yourself.
/stats block ~ ~-1 ~ set QueryResult $customGamerule Gamerules
Now every time the command block executes a command that provides a QueryResult
return value, fake player "$customGamerule" will have their "Gamerules" score set equal to that value.
The command that will be placed within that command block, which queries the value of the gamerule:
/gamerule customGamerule
In order to detect the fake player's value, /scoreboard players test
must be used.
/scoreboard players test $customGamerule Gamerules 1 1
Conditional. Command to run if the "customGamerule" gamerule is set to 1.
/say "customGamerule" is set to 1.
As long as the gamerule is set to "1" or "true", the /say
command will execute.
/scoreboard
changed in a few ways in 1.13, and some of it was split into new commands, but the core functionality remained