changing variable in 'if' statement, read it from other function.

Hello,

I have a script to change the value of an Int, yet when running a function that uses this variable it still uses the original value.

The intention is that if I sent a serial gdf after gdX (x a number between 1 and 15), it will sent out the previous value of the dimmer, yet it keeps being the default value 15.
my code:

#include <NewRemoteReceiver.h>
#include <NewRemoteTransmitter.h>
NewRemoteTransmitter transmitter(142, 9, 260, 2);
int stat_g = 0;
int value = 17;
int dimval = 15;
void setup() {
  Serial.begin(9600);
  Serial.setTimeout(200);
  NewRemoteReceiver::init(0, 2, checkcode);
}

void checkcode(NewRemoteCode receivedCode) {}

int getdimvalue(String incoming, String pt1) {
  if (incoming.length() == 4) {
    char valuept2 = incoming[3];
    String valuest = pt1 + valuept2;
    int value = valuest.toInt() ;
    int dimval = valuest.toInt();
    if (value < 16) {
      return value;
    } else {
      Serial.println("ERROR: DIMVALUE EXEEDS MAXIMUM");
      return NULL;
    }
  } else if(pt1 == "f") {
    Serial.println("dimfix");
    transmitter.sendUnit(1, true);
    return dimval;
  }
  else {
    //Serial.print("value: " + valuept1);
    dimval = incoming[2] - '0';
    String valuest = pt1;
    int value = incoming[2] - '0';
    return value;
  }
}

void loop() {
  if (Serial.available() > 0) {
    String incomingString = Serial.readString();
    incomingString.trim();
    if (incomingString.length() == 3 or incomingString.length() == 4) {
      char outlet = incomingString[0];
      char functie = incomingString[1];
      String valuept1 = String(incomingString[2]) ;
      valuept1.remove(2, 1);
      int dimval = getdimvalue(incomingString, valuept1);
      if (outlet == 'g' && functie == 'd') {
        transmitter.sendDim(1, dimval);
        delay(100);
        Serial.println(outlet + String(dimval));
      } 
    }
  }
}
      int dimval = getdimvalue(incomingString, valuept1);

Here you are creating a NEW local variable called 'dimval'. It is not going to use the global variable of the same name. To use the global variable, which will retain its value even after loop() exits, you have to remove the 'int':

      dimval = getdimvalue(incomingString, valuept1);
int dimval = 15;
      int dimval = getdimvalue(incomingString, valuept1);

I hesitate to say this, but not for long. It is stupid to have local and global variables with the same name. There are enough letters in the alphabet, and variable names can be any length, that there is no excuse for having local and global variables of the same name.