hey there, i was wondering if it is possible to use text within text files like variables, i am creating a custom scene that chooses the the text file to get information from depending on window id and page number, my text files are named like so: "file 1 1.txt" so that would be the window with the id of 1 at page 1, the reason i am mainly using the text files is that i am creating a large text field so it is easier to write the text in the text file and load it correspondingly, the windows also have other settings stored in arrays obtained from cases, so as you can tell i need to put a case in a case to get the right settings, example:
case id
when 0
case page
when 0 then []
when 1 then []
end
when 1
case page
when 0 then []
when 1 then []
end
end
so as you can see this method gets a bit messy after a while, and a little hard to keep track of stuff, so as i am already using a text file to store the text in would it be possible to create and read my arrays from my text file? so essentially i would dedicate the first few lines in the text file for variables, and use the rest for actual text strings, the method i am using to get my text file:
@text_file = IO.readlines("file #{@id} #{@page}.txt")
edit:
ok after been a little more clear headed today i think i came up with a pretty correct sollution, the main problem i was having is that the array that i was creating could be expended, for example i config image properties like so: [x, y, "NAME", opacity] then they go inside an array, and it can be expanded to the users desire to draw as many images as they like, then the second problem was that there is a string aswell as integers, anyway this is the method i came up with if anybody is interested, i think i went about it a pretty correct way, if anyone thinks otherwise let me know of a better sollution
def change_lore
#directory name
directory = "lore items"
#create directory if it doesnt exist
unless File.directory?(directory)
Dir.mkdir(directory)
end
#get filename depending on id and page
filename = "lore #{@lore_id} #{@page_number}.txt"
#the path to the file
path = ".\\#{directory}\\" + filename
#if the file exists
if FileTest.exist?(path)
#store the file
@lore_file = IO.readlines(path)
#setup picture config array
@picture_config = []
#get line in text document for picture config
config_line = @lore_file[1]
p config_line
#turn it into an array of strings
config = config_line.gsub!(/[\[\]]/,'').split(/\s*,\s*/)
p config
#loop amount of images configured
for i in 0...(config.size / 4)
#create the images config shell
@picture_config[i] = []
#loop through each configs string
for j in (i * 4)...((i * 4) + 4)
#if it is other that the string turn it into an integer
if j != (i * 4) + 2
@picture_config[i].push(config[j].to_i)
#if it is the string leave it as a string
else
@picture_config[i].push(config[j])
end
end
end
#print final result
p @picture_config
#print error if no text file found
else
print "NO TEXT FILE FOUND FOR CURRENT ITEM/PAGE"
exit
end
end
the line in my text file was like so "[0, 0, 0020, 255], [0 ,0, 0020, 255]" and it ended up like so [[0, 0, "0020", 255], [0 ,0, "0020", 255]]