set var1=123456789
set var2=abcdef
call :specialvars
echo %var1%, %var2%
rem More code...
:specialvars
setlocal
set var1=987654321
set var2=fedcba
endlocal
goto :eof
When inside the section setlocal
, endlocal
section, variables are seperate from the caller's variables, hence why %var1% and %var2% weren't changed.