Can I execute a txt file from a script?
#1
If I have a txt file called "Text" in my games data folder.
The content of this txt file is:

print "hi"

How can I execute this text file from an in-editor script?
Reply
#2
Try

Code:
file = File.open("Text", "rb")
file.each_line {|line|
  eval(line)
}
file.close
Reply
#3
Thanks a lot. It works ^^

EDIT:
when i have a whole class with lots of stuff in the txt document, I get the following error:

Syntax error occurred while running script
Reply
#4
That's simple, you have syntax error in the text file. Try copying the script from the text file to the RMXP scripts and run the game, then RMXP will tell you where the syntax error is.
Reply
#5
I tried, but I don't get any errors.

So, what I'm trying to do is to have the Scene_Title class in a txt document and load it into the game using the code charlie provided.
Reply
#6
Try with this code insteand:
Code:
file = File.open("Text", "rb")
eval(file.readlines)
file.close
Reply
#7
I'm closer now.
but It gives me the following error:

line 4: cannot convert array into string
Reply
#8
Ohh, sorry, I forget a bit of code:
Code:
file = File.open("Text", "rb")
eval(file.readlines.join)
file.close
Reply
#9
Thank you very much. You have been of great support ^^
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
   Is there a script to make train actors face the same way as the player? Ace_V 12 629 28 minutes ago
Last Post: Ace_V
   Lead Actor Swapper script error Ace_V 25 13,733 09-07-2025, 01:22 PM
Last Post: DerVVulfman
   Plugin or Script help with Item menu, SKill menu, and Equip menu JayRay 3 5,316 11-22-2024, 07:02 PM
Last Post: JayRay
   Script compatibility help Lord Vectra 3 9,541 07-25-2021, 11:42 PM
Last Post: DerVVulfman
   Adding face script on Cogwheel's RTAB Battle Status rekkatsu 15 29,678 08-25-2020, 03:09 AM
Last Post: DerVVulfman
   Map name as save file name Whisper 9 18,210 05-01-2020, 05:35 PM
Last Post: Whisper
   "Wait" in the script Whisper 13 27,666 04-28-2020, 04:06 PM
Last Post: Whisper
   Skill Cooldown script Fenriswolf 11 27,613 12-10-2019, 11:10 AM
Last Post: Fenriswolf
   Help iwth script (RGSS Player crash) Whisper 3 12,593 06-17-2017, 05:03 PM
Last Post: Whisper
   Help modifying a script Keeroh 7 16,689 06-11-2017, 04:43 PM
Last Post: DerVVulfman



Users browsing this thread: