The president is surely right that different settings call for different types of remarks, and that a campaign rally and a speech to a veterans’ organization demand different approaches. But that doesn’t really get very far. Trump has often shown utter tone deafness about what kinds of remarks are appropriate, for example in turning an appearance at the CIA into a political rally, or whining about his harsh treatment at the hands of the press during a commencement speech at the Coast Guard Academy.

Rucker’s reality-TV analogy, though seductive, doesn’t explain everything either. While Trump cares deeply about ratings, his most outrageous comments come at times when he appears to lose control of his emotions, rather than at intervals calculated to produce a story arc.

Instead, the difference between Trump’s behavior on various occasions seems to come down to two major factors: What was his last public appearance like? And does he stick to the teleprompter or not?

The president has established a pattern in his recent appearances of bouncing back and forth between sober statements, generally read directly from the page, and wild ones, generally improvised. Consider the record. On August 12, the day of violence in Charlottesville, Virginia, Trump made a statement that deplored violence “on all sides,” and which was widely condemned. While Trump spoke with a grim face, it was in fact improvising, free-wheeling Trump. Politico reported that Trump had a more typical response written out, but instead of reading it aloud, “the president veered from those prepared remarks.”

Following the pattern, we’d expect the next statement to be both restrained and tightly on script. In fact, under intense pressure, the president on August 14 made another statement—a straightforward condemnation of the Ku Klux Klan and neo-Nazis and a statement that “racism is evil.” Those remarks were ploddingly read straight from the page.

Then came August 15. Having been sober and on-script the day before, Trump was freewheeling and speaking for himself, and it went poorly. The president attempted to split hairs, arguing that while the Klan and white nationalists were bad, some of those who marched alongside them were “fine people.”

The pattern continues. On Monday, Trump delivered his speech about Afghanistan strategy, and while it was notably light on strategy, he’d lowered expectations far enough with his embrace of white supremacy that he won some praise for simply sticking to his written remarks and delivering another workmanlike, unremarkable address.

That set up the Tuesday debacle in Phoenix. Trump started out reading from prepared remarks, and the tone at the start of his rally stressed the need for unity and conciliation. Then he decided to freelance and speak for himself, and the remarks went off the rails, with blatant falsehoods, the suggestion that journalists are traitors, and attacks on Republican senators. As a result, it’s no surprise that the following day in Reno he was on script and lowkey.