Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 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
   Script compatibility help Lord Vectra 3 3,401 07-25-2021, 11:42 PM
Last Post: DerVVulfman
   Adding face script on Cogwheel's RTAB Battle Status rekkatsu 15 12,401 08-25-2020, 03:09 AM
Last Post: DerVVulfman
   Map name as save file name Whisper 9 8,046 05-01-2020, 05:35 PM
Last Post: Whisper
   "Wait" in the script Whisper 13 13,278 04-28-2020, 04:06 PM
Last Post: Whisper
   Skill Cooldown script Fenriswolf 11 13,703 12-10-2019, 11:10 AM
Last Post: Fenriswolf
   Help iwth script (RGSS Player crash) Whisper 3 6,379 06-17-2017, 05:03 PM
Last Post: Whisper
   Help modifying a script Keeroh 7 8,731 06-11-2017, 04:43 PM
Last Post: DerVVulfman
Question  Mog Menu script: help me stop the crazy picture movement during transitions Zachariad 4 8,408 05-31-2017, 05:10 AM
Last Post: Zachariad
   Actor names in Quest Script jreagan406 5 7,417 03-07-2017, 08:06 AM
Last Post: JayRay
   Bizarre issue with Lanzer counter script. Steel Beast 6Beets 2 6,517 10-04-2016, 11:46 AM
Last Post: Steel Beast 6Beets



Users browsing this thread: