Transfer parameter-value from loop to function

Hello @UKHeliBob,

I found our missunderstanding:
My challenge is to declarate the arguments within an if statement WITHOUT calling up the function. The function should be later called up by another if statement and should use the arguments, which are declared by an former if statement.

EDIT: So I would like to define "global" variables WITHIN the Loop. Or find another way to get the same result, if this way is not possible :slight_smile:

Ive compressed it into a code snipped to make it more understandable:

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "URTouch.h"
#define TFT_DC 2
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
#define t_SCK 3
#define t_CS 4
#define t_MOSI 5
#define t_MISO 6
#define t_IRQ 7
URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);
char currentpage;
int x, y;

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  if (currentpage == '0') {
      if (ts.dataAvailable()) {
      ts.read();
      x = ts.getX();
      y = ts.getY();

      if ((x >= 50) && (x <= 125) && (y >= 20) && (y <= 60)) { // button 1 clicked 
        
        int matchtime = 5000; // 5s testing time for this type is setted here
          
     }
      
      if((x>=200) && (x<=275) && (y>=20) && (y<=60)){ // button 2 clicked 
        
        int matchtime =2000;// 2s testing time for this type is setted here
             
               }
         }
  }

//(...)

 if (currentpage == '3')
  matching(); //function with arguments is called up here. The function should now run with value of arguments, which are defined at line 15 or 19 (depending on which button was clicked before). 
  
}

void matching(int matchtime) { //function, which is working with previously assigned parameters
  
  Serial.print("zeit=");
  Serial.print(matchtime); //prooves, that correct argument is used at function

}