[solved] Why is this giving an error

Wherever I put this:

public static bool whyNot = false;

It gives an error. I would very much like to declare public variables inside methods... Is that not possible, or what am I doing wrong?

The error is:

exit status 1
expected primary-expression before 'public'

The full sketch:

/* This is the code for turning the HiFi System On or Off according to the audio input.
    Written by Benedek Fodor.

    The rights of included libraries belong to their respective owners.
    This code is not public, I don't hold any responsibility for it.

    Version 0.3, Complete rewrite. Paying more attention to the aesthetics, and "logicallity". Implementing Blynk library.
    V 1.5 - different checking technique
    V 1.6 - implementing new phisical interface, complete rebuild of harware.
    V 1.7 - code rewrite, didn't work at all :D

//------------------------------------ Phisical interface pins
const int yellowButtonLeft = A2;
const int yellowButtonRight = 7;
const int redButton = A5;

const int yellowLedLeft = 10;
const int yellowLedRight = 9;
const int redLed = 11;

const int livingRoomRelays = A3;
const int kitchenRelays = 3;
const int hifiPowerRelay = 4;

//------------------------------------ Variables
bool kitchenSpeakers = false;
bool livingRoomSpeakers = false;
bool hifiState = false;
bool autoMode = false;

//------------------------------------ Libraries
#include <BlynkSimpleStream.h>
char auth[] = "6e6c4ee233224a9d913df84ce35dd2a1";

WidgetLED checking(V2);

//------------------------------------ Blynk button press events

//------------------------------------ Check for sound signal
void updateState() {
  static int updateI;
  static int shouldBeOn;
  static int shouldBeOff;
  if (!autoMode) return;

  if (check()) { //If momentary signal gets detected

    if (!hifiState) { //And HiFi is currently OFF

      while (updateI <= 3) {  //We check for signal 3 more times with time difference of 10 ms.
        if (check()) shouldBeOn++; //If there really is signal, the HiFi should be turned on.
      updateI = 0;

    } else { //But if HiFi is already ON,
      shouldBeOff = 0; //The HiFi shouldn't be turned OFF.

    if (shouldBeOn > 3) { //If we concluded 3 times, that the HiFi should get turned ON, we turn it on.
      hifiState = true;
      shouldBeOff = 0;

  else //If we don't detect a signal

    if (shouldBeOff > 20) shouldBeOn = 0; //      And we haven't detected signal for a while now, it's harder to keep the HiFi on. (This is needed, so despite random noise spikes, the HiFi can eventually turn OFF)
    if (hifiState) shouldBeOff++; //              And the HiFi is currently ON, it should get turned OFF.
    if (shouldBeOff == 150) hifiState = false; // And we haven't detected signal for a long while now, the HiFi gets turned OFF.


bool check() {

  int tempRead0 = analogRead(V0); //We collect two samples from the signal
  int tempRead1 = analogRead(V0);

  if (tempRead0 - tempRead1 > 3 || tempRead0 - tempRead1 < -3) return true; //If there is a big difference between the samples, we've got signal.
  else return false;

//------------------------------------ Deal with different inputs and interfaces
//Blynk button press events

BLYNK_WRITE(V10) { // kitchen //We store blynk button values to separate variables, and storing, that they have been updated.
  static public bool KS_Blynk = param.asInt(); //KS -> KitchenSpeakers
  static public bool KS_Diff = true

BLYNK_WRITE(V11) { // living room
  static public bool LRS_Blynk = param.asInt(); //LRS -> LivingRoomSpeakers
  static public bool LRS_Diff = true;

BLYNK_WRITE(V12) { // On / Off user write
  static public bool hifiState_Blynk = param.asInt();
  static public bool hifiState_Diff = true;

BLYNK_WRITE(V13) { // AUTO mode
  static public bool autoModeBlynk = param.asInt();
  static public bool autoModeDiff = true;

//Phisical User Interface
void phisicalUI() {
  static int YBL_Pressed;
  static int YBR_Pressed;
  static bool RB_Pressed;
  static unsigned long RB_Press_Time;
  if (digitalRead(yellowButtonLeft)) {
    if (YBL_Pressed >= 2) kitchenSpeakers = !kitchenSpeakers;
    else YBL_Pressed++;
  if (digitalRead(yellowButtonRight)) {
    if (YBR_Pressed >= 2) livingRoomSpeakers = !livingRoomSpeakers;
    else YBR_Pressed++;
  if (digitalRead(redButton)) { //If red button is pressed down
    if (!RB_Pressed) { //and before it wasn't
      RB_Pressed = true; //remeber, that it was, and when.
      RB_Press_Time = millis();
  } else if (RB_Pressed) { //If it's not pressed, but it was, depending on how much it was pressed, decide, what was intended.
    RB_Pressed = false;
    unsigned long RB_Length = millis() - RB_Press_Time;

I'm not done with it yetm that's why it doesn't have setup and loop.

Public keyword is used for fields + methods of a class only.

Oh! I see. So put it before the method. Well, actually, that makes way more sense :slight_smile:

public static bool whyNot = false;

That's java. This is C++