I want those two to switch their values, but it seems like I always end up with references and both having the same value.
What is the correct way to do it?
local tempVar = a[1];
a[1] = a[2];
a[2] = tempVar;
As far as I'm aware there's no command in Lua to say "switch the contents of these two variables", so you have to use a temporary holding variable to do it.