Creating Functions not working as hoped

Hi could anybody help as to why the led is not staying on when i press the button, i created a function to make things easier for more leds and now the led is not staying on, Any help would be appreciated! Thanks

byte button = 2; 
byte button2 = 3;
byte led = 15;   
byte led2 = 14;

byte val;
byte old_val;
byte state;

void setup () {

pinMode(button, INPUT_PULLUP);
pinMode(led ,OUTPUT);               
pinMode(button2, INPUT_PULLUP);         
pinMode(led2 ,OUTPUT);



}

void loop (){

buttonCommand(2, 15, 0, 0, 1);


}



int buttonCommand(byte button, byte led, byte val, byte old_val, byte state) {

    val = digitalRead(button);

  if( val == HIGH && old_val == LOW) {
state = 1-state;
delay (10);
}

old_val = val;

 if ( state == 1)
digitalWrite(led,HIGH);
else
digitalWrite(led, LOW);



}

These questions are about programming, not general project guidance. There is a specific forum for programming.

The difference in your code is that all the variables inside the function are local to that function. They don't remember their value from the last time the function was called, you pass them in each time.

In your second example, old_val is a global variable and retains its value over the lifetime of the program [repeated calls to loop()]

Ok thankyou and sorry for posting in the wrong forum.