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
   Plugin or Script help with Item menu, SKill menu, and Equip menu JayRay 3 128 11-22-2024, 07:02 PM
Last Post: JayRay
   Script compatibility help Lord Vectra 3 4,607 07-25-2021, 11:42 PM
Last Post: DerVVulfman
   Adding face script on Cogwheel's RTAB Battle Status rekkatsu 15 15,864 08-25-2020, 03:09 AM
Last Post: DerVVulfman
   Map name as save file name Whisper 9 10,226 05-01-2020, 05:35 PM
Last Post: Whisper
   "Wait" in the script Whisper 13 16,180 04-28-2020, 04:06 PM
Last Post: Whisper
   Skill Cooldown script Fenriswolf 11 16,499 12-10-2019, 11:10 AM
Last Post: Fenriswolf
   Help iwth script (RGSS Player crash) Whisper 3 8,536 06-17-2017, 05:03 PM
Last Post: Whisper
   Help modifying a script Keeroh 7 10,236 06-11-2017, 04:43 PM
Last Post: DerVVulfman
Question  Mog Menu script: help me stop the crazy picture movement during transitions Zachariad 4 9,878 05-31-2017, 05:10 AM
Last Post: Zachariad
   Actor names in Quest Script jreagan406 5 8,649 03-07-2017, 08:06 AM
Last Post: JayRay



Users browsing this thread: 2 Guest(s)