Problem with file("whatever.txt").read()

This is where all the old Lemma Soft-specific posts are (i.e. Tales of Lemma 1, Shoujo Attack!, and some Hanafuda Club). They are here for old times sake ^^
Locked
Message
Author
Ivlivs
Veteran
Posts: 252
Joined: Sun Feb 25, 2007 1:00 pm
Contact:

Problem with file("whatever.txt").read()

#1 Post by Ivlivs » Tue Mar 20, 2007 6:21 pm

I tried to include these lines of code into my work:

Code: Select all

$ name = file("Your name.txt").read()
$ s = Character('Someone', color="#c8ffc8")
$ r = Character(name, color="#c8ffc8")
Then I get a traceback error message stating that it cannot find the file "Your name.txt", even though the thing is in the directory with the rest of the script.

How do I fix this issue?

Ivlivs
Veteran
Posts: 252
Joined: Sun Feb 25, 2007 1:00 pm
Contact:

#2 Post by Ivlivs » Tue Mar 20, 2007 9:27 pm

I figured out the problem: you have to put the text file in the main Ren'Py directory (where the launcher is) rather than inside the game directory itself.

I have no idea how to make it read from the game directory.

Secondly, when I try to place into the variable a text file containing a single name in Japanese and nothing else, then call the variable using '%(variable)s', I get an error indicating that something is out of range.

The error looks something like this:

Code: Select all

I'm sorry, but an exception occured while executing your Ren'Py
script.

UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

While executing game script on line 20 of F:\VN\renpy-6.1.0\The Sandbox/game/script.rpy.

-- Full Traceback ------------------------------------------------------------

  File "renpy-6.1.0\renpy\bootstrap.py", line 166, in bootstrap
  File "renpy-6.1.0\renpy\main.py", line 275, in main
  File "renpy-6.1.0\renpy\main.py", line 92, in run
  File "renpy-6.1.0\renpy\execution.py", line 97, in run
  File "renpy-6.1.0\renpy\ast.py", line 250, in execute
  File "renpy-6.1.0\renpy\exports.py", line 461, in say
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

User avatar
PyTom
Ren'Py Creator
Posts: 15257
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#3 Post by PyTom » Tue Mar 20, 2007 9:39 pm

Try

$name = file(config.gamedir + "/Your Name.txt").read()

You need to tell it explicitly to look in the gamedir. To fix the encoding bug, you need to explicitly specify the encoding. The only one we really support is utf-8, so you want to save the text file as uf-8, and then write:

$ file(config.gamedir + "/Your Name.txt").read().decode("utf-8")
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Locked

Who is online

Users browsing this forum: No registered users