One tiny typo might be the cause! It looks like right under the elseif, you have unswap_tile(x.y) instead of unswap_tile(x,y) (period instead of a comma). See if that helps fix things. If not, let me know.
it was the problem thank you very much, would never have noticed it by myself. great tutorial btw