ich würde das so machen.

function var_change()
{
if(variable == 1){variable = 0;}
else{variable = 1;}
}

on_space == var_change();