can i treat text in a text file like a variable?

Started by diagostimo, October 20, 2012, 07:56:28 am

Previous topic - Next topic

diagostimo

October 20, 2012, 07:56:28 am Last Edit: October 20, 2012, 08:33:23 pm by diagostimo
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 :D

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]]

KK20

So I take it you have a way to keep people from being able to access and edit these files?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

diagostimo

im currently writing this script for someone else, part of the request was to be able to configure the item in its individual text file, but that gets me thinking now as i will make a public release of it, i have thought the process over and this is how i think ill go about:
script checks if file "lore #{@id} #{@page}.whatever" exists, if it exists it loads all the required data from that file, if it doesnt exist then it checks for the same named file with a .txt extension, converts all the data into the corisponding variables, then creates the file and saves the data to it, this would allow the creater to run the script to convert the data, then remove the text files after leaving them with the unaccessable data files, i actually got this idea from when i used to mod data for diablo 2, all there data was stored in .mpq files, if you decompressed those files you could get access to the files, all the data there was loaded by text files and stored in bin files, so you could simply go in and edit the text files, delete the bin file and recompress the archive, then when the game ran it would create the new bin file with your edits, they should have deleted there text files :p