Variable scope and tabs

I’m having a bit of trouble with declaring global variables.
I am trying to achieve a tab that contains a variable list.

Tab 1-

void setup()
{
Serial.begin(9600);
Variables();

}

void loop()
{
  Serial.print ("Initial humidity variable = ");
  Serial.print (humidity);
  ReadHumidity();
  Serial.print ("Final humidity variable = ");
  Serial.print (humidity);
  delay(20000);
}

Tab 2-

void Variables()
{
float humidity = 0;
float temperature = 0;
}

Tab 3-

void ReadHumidity()
{
    float hum=0;
    int i=0;
    float humread=0;
    for (int i=0; i <= 5; i++)
    
{
  humread = sht1x.readHumidity();
  hum = hum + humread;
  
  //Debugging print section.
  Serial.print ("hum ");
  Serial.print (i);
  Serial.print (" = ");
  Serial.print (hum);
}  
  
  humidity = hum / 5;
}

Compiling gives error:

In function ‘void loop()’:
error: ‘humidity’ was not declared in this scope In function ‘void ReadHumidity()’:

And highlights serial.print (humidity); in tab #1 / void loop().

I have also tried just listing variables in a tab by themselves, foregoing the subroutine call in void setup().
Any suggestions?

Each tab is a separate pde file. Global scope is limited to the file that a variable is defined in. If you want to share variables between pde files, that has to be done as arguments to functions or return values from functions.

Exactly what I was trying to avoid.
Thanks for the clarity of your answer!

You could try declaring your variables as extern.

//pde1
extern int test;

//pde2
extern int test;

Now both files should ‘see’ the test integer

Is the extern keyword required in both files? I thought it was needed only in the files that are trying to use a global variable defined in another file.

I think PaulS might be right.

I've coded php for a while now and the clock says 0117, maybe it's time to do something useful for a change... :wink:

Thanks all, that got me exactly where I wanted to be.

Just a side note on another hard learned lesson.

If the Arduino ide is spitting out weird compile errors,

Save and restart!