[SOLVED]Why it error amd how do I fix this?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
BigHa
Newbie
Posts: 15
Joined: Sun Jan 19, 2014 8:45 am
Contact:

[SOLVED]Why it error amd how do I fix this?

#1 Post by BigHa » Wed Jan 22, 2014 8:27 am

Write some code to write novel in to txt file after finish the game.
After I run it got error say "try: invalid syntax".How can I fix it? (I'm new in python.)
And I want txt file save in saves folder (place that renpy saved be saved there).How can I do that?

Code: Select all

##############################################################################
# Read & Write Text File
#
# :Use For Publish Novel Files. 

python hide:
        import os
         
        # The built-in function `open` opens a file and returns a file object.

        # Read mode opens a file for reading only.
        def readvn():
            try:
                f = open("vn.txt", "r")
            try:
                # Read the entire contents of a file at once.
                string = f.read() 
                # OR read one line at a time.
                line = f.readline()
                # OR read all the lines into a list.
                all = f.readlines()
                finally:
                f.close()
            except IOError:
                pass
            return
        
        def newvn(text):
            # Write mode creates a new file or overwrites the existing content of the file. 
            # Write mode will _always_ destroy the existing contents of a file.
            try:
            # This will create a new file or **overwrite an existing file**.
            f = open("vn.txt", "w")
            try:
                f.write(text) # Write a string to a file
                f.writelines(lines) # Write a sequence of strings to a file
            finally:
                f.close()
            except IOError:
                pass
            return

        def writevn(text):
            # Append mode adds to the existing content, e.g. for keeping a log file. Append
            # mode will _never_ harm the existing contents of a file.
            try:
                # This tries to open an existing file but creates a new file if necessary.
                f = open("vn.txt", "a")
            try:
                f.write(text)
            finally:
                f.close()
            except IOError:
                pass
            return

Last edited by BigHa on Wed Jan 22, 2014 1:00 pm, edited 1 time in total.

Timberduck
Regular
Posts: 60
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

Re: Why it error amd how do I fix this?

#2 Post by Timberduck » Wed Jan 22, 2014 12:16 pm

Which line is the syntax error?
usually syntax can be fixed with simply a press of the backspace or space button on your keyboard.

BigHa
Newbie
Posts: 15
Joined: Sun Jan 19, 2014 8:45 am
Contact:

Re: Why it error amd how do I fix this?

#3 Post by BigHa » Wed Jan 22, 2014 12:45 pm

Thanks! ,Timberduck
But I don't know how to get txt in saves folder.

BigHa
Newbie
Posts: 15
Joined: Sun Jan 19, 2014 8:45 am
Contact:

Re: Why it error amd how do I fix this?

#4 Post by BigHa » Wed Jan 22, 2014 1:00 pm

Ok,I found it. Thank you, Timberduck
Everything is SOLVED!

Post Reply

Who is online

Users browsing this forum: Google [Bot]