problem with \xA0 from ASCII-8BIT to UTF-8

recently i had received this error here, i didn't quite understand what it is,

is it some script error or is it my computer?



1678230806225.png



this is the 118 line:
Code:
 Dir.mkdir(APPDATA) if !Dir.exists?(APPDATA)

the entire code:

Code:
  APPDATA = "#{ENV['HOME']}/AppData/Local/game"
  Dir.mkdir(APPDATA) if !Dir.exists?(APPDATA)
  def self.save_file_exists?
    !Dir.glob("#{APPDATA}/Save.rvdata2").empty?
  end
Moved to: RGSSx Script Support

Might help if you say what script you're using.

I recognize some of it but I suppose others could be using similar code for other things.

Do you have any non-Latin characters in your Windows user name?
Let me guess... your username has a multibyte character or space inbetween that shouldn't be displayed on screen and now you're having this issue right? Since we're working with Ruby 1.9 or below, this might only be solved like this:

Method #1 - Ruby 1.9
Ruby:
env_home = "#ENV['HOME']}/AppData/Local/game"
APPDATA = env_home.force_encoding("ascii-8bit").gsub(/\W+/,"")

Method #2 - Ruby 1.8 or 1.9
Ruby:
env_home = "#ENV['HOME']}/AppData/Local/game"
APPDATA = env_home.unpack("A*").to_s.gsub(/\\x\w{2}|\W+/,"")

Replace "" with " " if it's supposed to be a simple space there.
In this case, the order of the replacements of the matched regular expressions do matter here.

Other solutions might tell you that you need to use iconv, but it'd be way better for the average game developer to keep it as simple as possible as shown above.
Moved to: RGSSx Script Support

Might help if you say what script you're using.

I recognize some of it but I suppose others could be using similar code for other things.

Do you have any non-Latin characters in your Windows user name?
yes, my pc has a name with a special character like á, ô, ã so that must be the problem of the script not from my computer

Let me guess... your username has a multibyte character or space inbetween that shouldn't be displayed on screen and now you're having this issue right? Since we're working with Ruby 1.9 or below, this might only be solved like this:

Method #1 - Ruby 1.9
Ruby:
env_home = "#ENV['HOME']}/AppData/Local/game"
APPDATA = env_home.force_encoding("ascii-8bit").gsub(/\W+/,"")

Method #2 - Ruby 1.8 or 1.9
Ruby:
env_home = "#ENV['HOME']}/AppData/Local/game"
APPDATA = env_home.unpack("A*").to_s.gsub(/\\x\w{2}|\W+/,"")

Replace "" with " " if it's supposed to be a simple space there.
In this case, the order of the replacements of the matched regular expressions do matter here.

Other solutions might tell you that you need to use iconv, but it'd be way better for the average game developer to keep it as simple as possible as shown above.
i've tried using these two, but it doesn't seem to work, the game starts, but it doesn't create the folder in appdata
A bit of google searching and this may be an option
APPDATA = "#{Dir.home}/AppData/Local/game"
A bit of google searching and this may be an option
APPDATA = "#{Dir.home}/AppData/Local/game"
It shouldn't be for it's another way to call the HOME environmental variable.

My code should have worked there because of what \xA0 stands for: "A non-breaking space is a space character that prevents line breaks and word wrapping between two words separated by it."

So he better changes the username, if Windows does change the directory's name automatically... but I suspect it doesn't. That would mean he'd need to create a new Windows user account. Yeah, that's not an idea any of us would ever like...

I gotta test it in case there's a tilde or accent involved there but that's not what his original error message tells us.
yes, my pc has a name with a special character like á, ô, ã
I gotta test it in case there's a tilde or accent involved there

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-xa0-from-ascii-8bit-to-utf-8.155618/