Text Question.

Non-platform specific questions.

Text Question.

Postby Jay S. » Sat Jun 09, 2007 8:23 pm

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!
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby DilloDude » Sun Jun 10, 2007 6:31 am

The simplest way would probably be to read all the texts into an array. Then you can select one string from the array.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Jay S. » Sun Jun 10, 2007 6:22 pm

Okay, so... how would I do this? :oops: (Don't worry, it's my goal to learn C better...)
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby Sgt. Sparky » Sun Jun 10, 2007 6:32 pm

I will make a line counting and selecting function, just a minute, I must do some stuff real quick. :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Jay S. » Mon Jun 11, 2007 7:41 pm

Sparky....

Anything yet? :(
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby Sgt. Sparky » Mon Jun 11, 2007 9:56 pm

Jay S. wrote:Sparky....

Anything yet? :(

sorry,
I will work on that now or soon,
I had to get off the computer. :(
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Jay S. » Mon Jun 11, 2007 10:16 pm

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...
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby Sgt. Sparky » Mon Jun 11, 2007 10:21 pm

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?
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Sgt. Sparky » Tue Jun 12, 2007 12:15 am

Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Jay S. » Tue Jun 12, 2007 12:55 am

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...
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby Sgt. Sparky » Tue Jun 12, 2007 2:34 pm

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
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Jay S. » Tue Jun 12, 2007 3:27 pm

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. :(
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby Sgt. Sparky » Tue Jun 12, 2007 5:06 pm

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
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Jay S. » Tue Jun 12, 2007 8:28 pm

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:
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby Sgt. Sparky » Tue Jun 12, 2007 10:33 pm

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
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest