Understanding this line " ? HIGH : LOW; "

Zoandar:
The commands I need to understand are the "button.update" and "button.read" used in this function (subroutine) of the larger BinaryDiceGame Sketch. I am guessing button.read means read the state of the button. What is "button.update"?

OK, I got a bit off-track, sorry. :slight_smile:

Let's get the terminology straight first. They are functions, not commands. And the code is trying to call them. Let me explain ...

This is a function:

int foo ()
  {
  return 42;
  }

If you "call" it, it returns a value (42 in this case). This is how you might call it:

int a;
a = foo ();

Now after calling it, the variable "a" will contain 42.

Functions can take "arguments", for example:

int bar (int x)
  {
  return x + 42;
  }

Now you call it by passing a parameter:

int a;
a = bar (3);

Now after calling it, the variable "a" will contain 45.

I know that button.update is a function (without reading any more code) because it is followed by parentheses. Like in the example above, when we called "foo".

Just to explain, this is not a function call:

int a;
a = foo;

No brackets after foo, so it is just assigning the contents of foo into a.

This is not a function call:

int a;
a = bar + (3);

This is because there is an "operator" between bar and (3). So we are adding 3 to bar, and assigning the result to a. The brackets are just for precedence, like this:

int a;
a = bar + 4 * (2 + 3);

In this case the brackets just say "add before multiply".

Back to your example. Both guess_button.update() and guess_button.read() are function calls, because there are brackets, and nothing between the function name and the brackets. So you have to search the code (or maybe the library) to see what the functions do. Clearly they are not taking arguments (like my "bar" function did) because there is nothing inside the brackets. But the brackets have to be there, or they aren't function calls.

The next issue is the dot. Really you have two things here: "guess_button" and "update". I am guessing that "guess_button" is an instance of a class of some sort, and "update" is a member function. So really, somewhere "inside" the class of which guess_button is an instance, is a function called update.

The general idea of classes is they describe a general thing. For example, you, Zoandar are a person. So, "person" is a class of things, and Zoandar is an instance (one of) that class.

Moving on from guess_button.update() to the "if" part. An "if" statement executes the true branch if the "thing inside the brackets" is non-zero. Like this:

if ( foo() )
  {
  // do if true
  }
else
  {
  // do if false
  }

So based on my earlier example of the function foo, what is happening is that it calls foo first, and gets back a number (in this case 42). If the number is not zero the "true" part is executed, otherwise the "false" part (if any).

In this example:

if (guess_button.read() == HIGH)

This is calling the function guess_button.read(). Presumably that returns HIGH or not. If it returns HIGH then the compare will result in a true value (that is, non-zero) and the "true" branch of the "if" will be taken, otherwise not.