reading and writing strings

Posted By: Nowherebrain

reading and writing strings - 12/20/10 18:09

I'm not so new but I am having trouble, and I saw this as something that could go in the beginner area, as I am stumped...
does anyone have an example or know of an example of reading specific strings from a file into specific strings of a text?
I can load a text using "txt_load" and I can read and write to TEXT*.pstring[x], but getting very specific pstring to pstring I am having issues. any example would be helpful.
Posted By: Superku

Re: reading and writing strings - 12/20/10 18:47

Please give an example of what you are trying to do.
Posted By: Nowherebrain

Re: reading and writing strings - 12/21/10 02:48

something to this effect, but it does not work...
the texts and the entitys are defined in another script that hold all the variables and filed data.....
I'd really like to just read it into one text object from a specific line and stop reading at another line, but....I have no clue how to do that....
Code:
function get_quest_file()
{
	quest_id = NPC_active.skill11;
	if(quest_id == 1000)
	{
		txt_load(dialogue_txt,"quest_1000.txt");
		file_str_write ((temp_txt.pstring)[0],(dialogue_txt.pstring)[3]);
		file_str_write ((temp_txt.pstring)[1],(dialogue_txt.pstring)[4]);
		file_str_write ((temp_txt.pstring)[2],(dialogue_txt.pstring)[5]);
		
	}
}


Posted By: MrGuest

Re: reading and writing strings - 12/21/10 11:53

wouldn't you juse use str_cpy() when copy data from one text to another.

If you specify it is what you're doing there probably is an easier way to do it rather than transferring the text twice.
Posted By: Nowherebrain

Re: reading and writing strings - 12/21/10 14:43

yes probably, but I am storing quests in separate files, and....and.......I had not even thought about str_cpy...I always have to make things more difficult...I will rewrite the function. Thank you.
Posted By: Nowherebrain

Re: reading and writing strings - 12/21/10 16:20

well, I was able to get it to work by loading a text and just setting the text objects size with wrap flag set, then I don't need to do line feeds...but I would still like to use string compare so I can read from specific points, but I think I can figure it out....
Posted By: Pappenheimer

Re: reading and writing strings - 12/21/10 18:08

fogman posted a good solution some weeks ago:
"fileparser"
He wrote two functions, one for strings and one for variables.
file_seek sets the reading cursor to the beginning of the file, file_find, finds the string, and the line after that reads the string or the variable after the found string.
Posted By: fogman

Re: reading and writing strings - 12/21/10 18:15

You have to define gvFileParserHandle global when you want to use this snippet:

var gvFileParserHandle = 0;
var gvVideoMode;
.
.
.
function ReadVar()
{
gvFileParserHandle = file_open_read("yourfilename.txt");
gvVideoMode = FileparserVar("VIDEO_MODE = ");
file_close(gvFileParserHandle);
}


In the textfile you would write:

VIDEO_MODE = 8

The function will read the value right after the defined search string.

You should also take a look at strio.c in the GS include folder.
Posted By: Nowherebrain

Re: reading and writing strings - 12/21/10 20:37

thanks guys, but I was able to work it out....and I am using strio.c...lol
Thank you.
© 2024 lite-C Forums