Whitespace characters breaking the code

Hello, I've been encountering this issue for a while, whenever I code, I sometimes run into runtime errors because some whitespace character is interpreted as something else, I get errors like:
NameError: undefined local variable or method ` ' for #<Scene_TBS_Battle:0xd011f00>.
It sometimes invalidates a method name by not recognizing ` method' or a few times `method '(though I'm less sure about this error).

I'm using Windows 10 and my keyboard is CMS (Canadian Multilingual Standard), I suspect I sometimes press the wrong key and that leads to a dead key that would be invisible in the editor.
Do you know of a way of detecting those dead keys or maybe the issue is something else?
I can't help you, but I noticed errors when I used google translate on some scripts and when pasted into the editor it sees the whitespace in front as invalid characters. When i delete them and use space bar then it works fine.
So that's similar to what you are doing.
Maybe you have some "Non-breaking space" in the code.



Bash:
$ echo toto | grep "t"
-bash: $'\302\200grep' : commande introuvable
I'm unsure about your second part with bash commands lines as they did not make much sense to me.

I tried to grep with the unicode characters listed at the end of the wikipedia page with:
Bash:
grep $"\u00A0" core.rb
And so on with \u2007, \u202F, \uFEFF and \u2060, but the grep did not find any match, that being said maybe my file is not faulty or I did not list the proper characters, or the encoding does not match maybe?

I will try to save the faulty file or line next time I encounter the issue and run analysis on it, thank you.
My Theory: You could save the text in an ISO-number format first and then back as UTF-8. At some point some of the non-translatable characters should show up.
I'm unsure about your second part with bash commands lines as they did not make much sense to me.


It was just an example. The symbol after the pipe was not a space but an NBSP. Hence the error with the command "NBSPgrep" not found.
A long time ago, I don't remember which unix and keyboard config I used, but pressing "AltGr + space" was writing an NBSP. Sometimes, when I typed the pipe symbol (AltGr + 6 on a french keyboard) followed by a space, I accidentally added the NBSP instead of a regular space.
And I got this error "command grep not found", it took me some time to realize what was happening, making me crazy.

Another time when the NBSP symbol made me crazy was when trying to make some macros in WoW, some spells had an NBSP in their names so it was easier to copy it than type it ^^
When i delete them and use space bar then it works fine.
I tend do do the same when I meet these issues, yes rewriting the faulty whitespaces with spaces tend to fix the problem.

My Theory: You could save the text in an ISO-number format first and then back as UTF-8. At some point some of the non-translatable characters should show up.
I did, it did not seem to show unexpected characters, that being said, maybe my file was ok (which is good news x) ), I will try this again if I meet another runtime issue and I save it instead of deleting it. Thanks for the suggestion.

A long time ago, I don't remember which unix and keyboard config I used, but pressing "AltGr + space" was writing an NBSP. Sometimes, when I typed the pipe symbol (AltGr + 6 on a french keyboard) followed by a space, I accidentally added the NBSP instead of a regular space.
Actually I almost always meet this issue with boolean operations whenever I use || and since I also use AltGr on my keyboard for the pipe symbol this might be the source of the problem!

And I just wrote a small code like this AND YES IT BREAKS WITH THIS ERROR! (can't believe I'm happy to meet a bug).

Soooo, actually I made a mistake in my grep line, I should have done:
Bash:
grep $'\u00A0' core.rb
(double quote was not working compared to single quote, I suppose that's because it tried to find a string instead of a char)
And guess what? There was a faulty line! 😀
I'm sorry Core 0.10, you have yet another bug x)

Note that Emacs does see the non-breaking whitespace, but not VX Ace script editor.

Anyway, I think that solves it, thank you all for your answers, that was really helpful 🙂

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/whitespace-characters-breaking-the-code.182791/