Why do empty spaces cause syntax error?

Whenever I try to copy and paste a script from the forum or from the Steinberg’s developer site, the script module gives me a syntax error. This script is copied from the developer site:

-- find all effects and print their names
effects = this.program:findEffects(true)
 
if effects[1] then
    for i, effect in ipairs(effects) do
        print(effect.name)
    end
else
    print("Could not find any effects!")
end

The script is perfectly ok when typed in manually.

But when I copy and paste it I get this: _Syntax Error: 3: unexpected symbol near char(194):
_
After deleting the empty line 3 the first error is fixed but then I get this:
Syntax Error: 4: unexpected symbol near char(194): for i, effect in ipairs(effects) do

Does anyone know why is this happening and how to fix this?

I’ve had the same issue.

I suspect when you copy scripts from the developer site you use double click to select all, as their tool tip suggests.

For some reason this ads a few blank or “space” ascii characters to the copied script. I’ve found if you select all text by the normal click and drag way (bottom to top is easiest), you avoid this issue.

Thanks AposMus.

At least I know I’m not the only one having this issue.
Unfortunately doing it the way you suggested doesn’t work for me either. I can copy it line by line which is not really efficient.

Thanks for confirming.

You guys are a life saver! I was ready to throw my computer in frustration lol.

I always use an external editor such as Atom or VSCode with lua extensions. They show pretty quickly if there is something fishy about your code and you can clean up whitespace stuff. The only annoying thing is that you need to save your script in a lua file before the external editor can open it.
You can configure the external editor in options. Now when you click the edit button it will open the external editor instead of the annoying built in. I guess the build in is really just for glimpsing at a script or making a quick change.