Compare Stuff with Boolean Conditions

images/450px-On-Off_Switch.jpg

if statements decide what to run based on whether something is true. But just what is true?

Besides numbers and strings that we’ve seen, you can also make a variable that keeps track of whether something is turned on, like a toggle switch. In Minecraft, we’ll use this to determine all sorts of things: if a player is on the ground or not, if a string matches another string, whether to use a game event or ignore it, and much more.

Java calls this kind of variable a boolean,[21] and it can be assigned true or false, or you can give it math expressions using any of these operators, all of which return either ...

Get Learn to Program with Minecraft Plugins, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.