VXAce Event adding .txt. file in Game directory

Note : This is for VXAce ONLY. ^^
(Put this script in an event!)

-

unless File.exist?("sample.txt")
file = File.open("sample.txt", "w")
file.puts("Replace this text")
file.close
end
-

If the .txt file already exists within the game directory, it shouldn't create the file anymore (unless removed again).

Replace [ sample ] and [ Replace this text ] with anything you'd like.
unless File.exist?("sample.txt")
file = File.open("sample.txt", "w")
file.puts("Replace this text")
file.close
end
-

If the .txt file already exists within the game directory, it shouldn't create the file anymore (unless removed again).
Whoa, I didn't even know you can prevent a .txt file overwrite! You youngsters are good at making me feel stupid. Thank you!

EDIT: Okay so actually I have an issue, and it's for the creation of .txt files with more than one line. For example, in my game, I have this Easter egg that prints an ASCII art of the main character's face:
File.open("thankyou2.txt", 'w') do |file|
file.print "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄&J .... :Y▄\n"
file.print "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄#J: ....... :\n"
file.print "▄▄▄▄▄▄▄▄PP~^^^^:.JJB##B#P~. \n"
file.print "▄▄▄▄&Y~^.~55555PY~~~~5&▄▄▄P \n"
file.print "▄▄#J:..^5JJ?YGBBB5J~~^^J&▄▄P\n"
file.print "▄&^ ::~5BP75YPBBGYP75BP~!&▄▄\n"
file.print "&:.:::7#G B:Y#BBBG B.Y##J^▄▄\n"
file.print ".:::.7BBG.G:YBGPGG.G:YBBBY:▄\n"
file.print " :::~YBBBG?5BB57??775BBBB5.▄\n"
file.print " :.JBBBBBBBBBBBBBPP?7?PBB5.▄\n"
file.print "B.JBBBBBBBBBBBBBGYY77YG#Y^#▄\n"
file.print "▄B~Y#BBBG^GBBB5!?YYBBB#?!B▄▄\n"
file.print "▄▄G?JPBBBY7777YBBBBBBP?JB▄▄▄\n"
file.print "▄▄▄▄BJ7?PPBBBBBBBPP??YB▄▄▄▄▄\n"
file.print "▄▄▄▄▄▄&#JJ777777?YY&&▄▄▄▄▄▄▄\n"
file.print "Thank you for playing !\n"
file.print "Created at : #{Time.now}"
end
Adding the "unless File.exist?("thankyou2")" command before this makes the game crash.
EDIT: Okay so actually I have an issue, and it's for the creation of .txt files with more than one line. For example, in my game, I have this Easter egg that prints an ASCII art of the main character's face.
Adding the "unless File.exist?("thankyou2")" command before this makes the game crash.
Tested your code, no issue, did you add the keyword end to quit the block set by the unless statement?
Like this:

Ruby:
unless File.exist?("thankyou2.txt")
    File.open("thankyou2.txt", 'w') do |file|
        file.print "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄&J .... :Y▄\n"
        file.print "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄#J: ....... :\n"
        file.print "▄▄▄▄▄▄▄▄PP~^^^^:.JJB##B#P~. \n"
        file.print "▄▄▄▄&Y~^.~55555PY~~~~5&▄▄▄P \n"
        file.print "▄▄#J:..^5JJ?YGBBB5J~~^^J&▄▄P\n"
        file.print "▄&^ ::~5BP75YPBBGYP75BP~!&▄▄\n"
        file.print "&:.:::7#G B:Y#BBBG B.Y##J^▄▄\n"
        file.print ".:::.7BBG.G:YBGPGG.G:YBBBY:▄\n"
        file.print " :::~YBBBG?5BB57??775BBBB5.▄\n"
        file.print " :.JBBBBBBBBBBBBBPP?7?PBB5.▄\n"
        file.print "B.JBBBBBBBBBBBBBGYY77YG#Y^#▄\n"
        file.print "▄B~Y#BBBG^GBBB5!?YYBBB#?!B▄▄\n"
        file.print "▄▄G?JPBBBY7777YBBBBBBP?JB▄▄▄\n"
        file.print "▄▄▄▄BJ7?PPBBBBBBBPP??YB▄▄▄▄▄\n"
        file.print "▄▄▄▄▄▄&#JJ777777?YY&&▄▄▄▄▄▄▄\n"
        file.print "Thank you for playing !\n"
        file.print "Created at : #{Time.now}"
    end #end of the open block
end #end of the unless statement
Tested your code, no issue, did you had the keyword end to quit the block set by the unless statement?
Like this:

Ruby:
unless File.exist?("thankyou2.txt")
    File.open("thankyou2.txt", 'w') do |file|
        file.print "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄&J .... :Y▄\n"
        file.print "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄#J: ....... :\n"
        file.print "▄▄▄▄▄▄▄▄PP~^^^^:.JJB##B#P~. \n"
        file.print "▄▄▄▄&Y~^.~55555PY~~~~5&▄▄▄P \n"
        file.print "▄▄#J:..^5JJ?YGBBB5J~~^^J&▄▄P\n"
        file.print "▄&^ ::~5BP75YPBBGYP75BP~!&▄▄\n"
        file.print "&:.:::7#G B:Y#BBBG B.Y##J^▄▄\n"
        file.print ".:::.7BBG.G:YBGPGG.G:YBBBY:▄\n"
        file.print " :::~YBBBG?5BB57??775BBBB5.▄\n"
        file.print " :.JBBBBBBBBBBBBBPP?7?PBB5.▄\n"
        file.print "B.JBBBBBBBBBBBBBGYY77YG#Y^#▄\n"
        file.print "▄B~Y#BBBG^GBBB5!?YYBBB#?!B▄▄\n"
        file.print "▄▄G?JPBBBY7777YBBBBBBP?JB▄▄▄\n"
        file.print "▄▄▄▄BJ7?PPBBBBBBBPP??YB▄▄▄▄▄\n"
        file.print "▄▄▄▄▄▄&#JJ777777?YY&&▄▄▄▄▄▄▄\n"
        file.print "Thank you for playing !\n"
        file.print "Created at : #{Time.now}"
    end #end of the open block
end #end of the unless statement
I am really stupid. Thank you very much! 😍

Original thread: https://forums.rpgmakerweb.com/threads/event-adding-txt-file-in-game-directory.178887/