Title line says it all really, I'm trying to convert a txt file to be read as a script, using the built-in eval command that's supposed to evaluate a string. Now Yeah, here's my minimalistic attempt (doesn't include stuff like no comment line reading yet, but hey - I was trying to get it working first :p )...
[rgss]module ScriptReader
#--------------------------------------------------------------------------
def self.lineup?(id)
entries = Dir.entries('Scripts/.')
for entry in entries
return true if entry.include?('RGSS' + id)
end
return false
end
#--------------------------------------------------------------------------
def self.script_content(id)
file = File.open('Scripts/RGSS' + id + ".txt")
content = file.readlines
return content
end
#--------------------------------------------------------------------------
end
begin
Graphics.freeze
entries = Dir.entries('Scripts/.')
for id in '01'..'99'
break unless ScriptReader.lineup?(id)
script = ScriptReader.script_content(id)
for line in script
line.gsub('/n', '')
eval(line)
end
end
$scene.main while $scene != nil
end
[/rgss]
I get undefined errors when I run this reading some scripts, so I figure eval totally isn't meant to push scripts into the interpreter for permanent use, but more like for instant effect. I'd still like to see a solution for this, so here's my barebones script, if you can work anything out, please post it ^^
Just if anyone's interested, this was tested with my Database Flag reader script linked in my signature - if it should work for you, try it with that script!
[rgss]module ScriptReader
#--------------------------------------------------------------------------
def self.lineup?(id)
entries = Dir.entries('Scripts/.')
for entry in entries
return true if entry.include?('RGSS' + id)
end
return false
end
#--------------------------------------------------------------------------
def self.script_content(id)
file = File.open('Scripts/RGSS' + id + ".txt")
content = file.readlines
return content
end
#--------------------------------------------------------------------------
end
begin
Graphics.freeze
entries = Dir.entries('Scripts/.')
for id in '01'..'99'
break unless ScriptReader.lineup?(id)
script = ScriptReader.script_content(id)
for line in script
line.gsub('/n', '')
eval(line)
end
end
$scene.main while $scene != nil
end
[/rgss]
I get undefined errors when I run this reading some scripts, so I figure eval totally isn't meant to push scripts into the interpreter for permanent use, but more like for instant effect. I'd still like to see a solution for this, so here's my barebones script, if you can work anything out, please post it ^^
Just if anyone's interested, this was tested with my Database Flag reader script linked in my signature - if it should work for you, try it with that script!