After modifying your edit a bit. It achieves what I want. Your original edit has the error of null value (somehow). I'll just share my edit.
if (Input.isPressed('left') && $gameSwitches.value(n)) dx -= 1;
if (Input.isPressed('right') && $gameSwitches.value(n)) dx += 1;
if (Input.isPressed('up') && $gameSwitches.value(n)) dy -= 1;
if (Input.isPressed('down')&& $gameSwitches.value(n)) dy += 1;
Not exactly a pretty code, but it works. Thanks for your help.