Page 1 of 2

Text Question.

PostPosted: Sat Jun 09, 2007 8:23 pm
by Jay S.
I tried searching the forum for my answer, but I couldn't find exactly what I needed. :( And so, here goes:

I know how to read text from a file, but how would I go about selecting which line in the text file I wanted to display in GE? For example, if I wrote a text file with dialogue for some NPCs in a game, how would I choose which line I want to display, corresponding to each NPC?

Sorry if this has been asked a number of times before, but I could use the aid. Thanks!

PostPosted: Sun Jun 10, 2007 6:31 am
by DilloDude
The simplest way would probably be to read all the texts into an array. Then you can select one string from the array.

PostPosted: Sun Jun 10, 2007 6:22 pm
by Jay S.
Okay, so... how would I do this? :oops: (Don't worry, it's my goal to learn C better...)

PostPosted: Sun Jun 10, 2007 6:32 pm
by Sgt. Sparky
I will make a line counting and selecting function, just a minute, I must do some stuff real quick. :D

PostPosted: Mon Jun 11, 2007 7:41 pm
by Jay S.
Sparky....

Anything yet? :(

PostPosted: Mon Jun 11, 2007 9:56 pm
by Sgt. Sparky
Jay S. wrote:Sparky....

Anything yet? :(

sorry,
I will work on that now or soon,
I had to get off the computer. :(

PostPosted: Mon Jun 11, 2007 10:16 pm
by Jay S.
Sgt. Sparky wrote:sorry,
I will work on that now or soon,
I had to get off the computer. :(


Oh, don't worry about it. :) I'd just like to know how to do this so I can know how to plan my project...

PostPosted: Mon Jun 11, 2007 10:21 pm
by Sgt. Sparky
Jay S. wrote:
Sgt. Sparky wrote:sorry,
I will work on that now or soon,
I had to get off the computer. :(


Oh, don't worry about it. :) I'd just like to know how to do this so I can know how to plan my project...

do you want it to count lines or copy a selected line?

PostPosted: Tue Jun 12, 2007 12:15 am
by Sgt. Sparky

PostPosted: Tue Jun 12, 2007 12:55 am
by Jay S.
Nevermind, I found another way to do it, I got it to work!!!!!!! :mrgreen: I used the standard code to read from a text file (found in the GE documentation for fopen), and then I used this:

Code: Select all
int n = 0;//number here corrisponds to which line is being read!)
strcpy(actor.text, textArray[n]);


I didn't know what that did. :oops: Sorry...

PostPosted: Tue Jun 12, 2007 2:34 pm
by Sgt. Sparky
Jay S. wrote:Nevermind, I found another way to do it, I got it to work!!!!!!! :mrgreen: I used the standard code to read from a text file (found in the GE documentation for fopen), and then I used this:

Code: Select all
int n = 0;//number here corrisponds to which line is being read!)
strcpy(actor.text, textArray[n]);


I didn't know what that did. :oops: Sorry...

just use my code, it works perfectly. :D
(yours does not work because it is just copying one part of the array. :()
but your code will not work because to copy one part of the array you must use,
strcpy(actor.text, &textArray[n]);
only if textArray is a declared text array. :D

PostPosted: Tue Jun 12, 2007 3:27 pm
by Jay S.
Sgt. Sparky wrote:just use my code, it works perfectly. :D


No, it doesn't. :lol:

When I tried using it in the Global Code, I got this error message:

Error line 18: undeclared identifier temp
Error line 19: undeclared identifier temp

Sgt. Sparky wrote:(yours does not work because it is just copying one part of the array. )
but your code will not work because to copy one part of the array you must use,
strcpy(actor.text, &textArray[n]);
only if textArray is a declared text array.


I have NO idea what you're talking about. :(

PostPosted: Tue Jun 12, 2007 5:06 pm
by Sgt. Sparky
Jay S. wrote:
Sgt. Sparky wrote:just use my code, it works perfectly. :D


No, it doesn't. :lol:

When I tried using it in the Global Code, I got this error message:

Error line 18: undeclared identifier temp
Error line 19: undeclared identifier temp

Sgt. Sparky wrote:(yours does not work because it is just copying one part of the array. )
but your code will not work because to copy one part of the array you must use,
strcpy(actor.text, &textArray[n]);
only if textArray is a declared text array.


I have NO idea what you're talking about. :(

you must make a string that is an actor variable called temp. :D

PostPosted: Tue Jun 12, 2007 8:28 pm
by Jay S.
Thanks, Sparky, that's a very useful code; but unless I'm missing something, I'm afraid to say that it's not quite what I'm looking for. :(

I'm not looking to copy another actor's text, I'm looking to copy text from a external text file and use it as dialogue. But, up to this point, I might not end up using this, because I realized I wouldn't be able to use the n\ to break lines. :P In my project, it would be RPG-style text, and that would be invaluable...

I didn't want to use script to not use so much of it for performance sake, so I could just try to make my own functions to try to simplify it...

Sorry I'm such a pest. :( :lol:

PostPosted: Tue Jun 12, 2007 10:33 pm
by Sgt. Sparky
Jay S. wrote:Thanks, Sparky, that's a very useful code; but unless I'm missing something, I'm afraid to say that it's not quite what I'm looking for. :(

I'm not looking to copy another actor's text, I'm looking to copy text from a external text file and use it as dialogue. But, up to this point, I might not end up using this, because I realized I wouldn't be able to use the n\ to break lines. :P In my project, it would be RPG-style text, and that would be invaluable...

I didn't want to use script to not use so much of it for performance sake, so I could just try to make my own functions to try to simplify it...

Sorry I'm such a pest. :( :lol:

oooh,
:lol:
I thought you ment to copy a specefied line. xD
make a string called temp.
then:
just use this for reading your text file from a normal external text file,
Code: Select all
FILE*txt;
txt = fopen("yourtextfilename.txt", "r+");
fread(&temp, sizeof(txt), 1, txt);
fclose(txt);
strcpy(yourtextactor.text, temp); 

that should work, let me test it. :D