Text strings

Game Editor comments and discussion.

Text strings

Postby Leif » Tue Aug 31, 2010 5:34 am

Hi :)

How can i load text strings into text actors from simple .txt file ?
And can GE make copy/paste actions with text data ?
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Text strings

Postby skydereign » Tue Aug 31, 2010 5:58 am

To do all of this you need to know how to use strings pretty efficiently. Also it really depends on what is in the .txt file that you want to read.

This is how to load text from a file into your text actor.
Code: Select all
FILE * textFile = fopen("filename.txt", "r");
fgets(text, 255, textFile);
fclose(textFile);


And to copy/paste strings you can use strcpy, which literally copies the second argument into the first. If you want to add the text onto the end of another string, you would use strcat... and so on.
Code: Select all
strcpy(string_0, string_1); // copies contents of string_1 into string_0
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Text strings

Postby Leif » Tue Aug 31, 2010 6:21 am

what is "r" in == FILE * textFile = fopen("filename.txt", "r"); == ?

i want to do:
.txt file with 150 strings
load: 1-st string into array[1], 2-nd string into array[2] etc.

About copy/paste
i mean - Ctrl+c copy in another place ( microsoft word for example) an Ctrl+p into text actor.
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Text strings

Postby skydereign » Tue Aug 31, 2010 6:30 am

fopen takes a mode, which is the "r" in this case.
"r" opens a text file for reading
"w" opens/creates a text file (it will discard previous contents)
"a" opens/creates a text file and places you at the end (append)
"r+" opens a text file for read and write
"w+" create a text file for read and write (it will discard previous contents)
"a+" opens/create a file for update and places you at the end

If you want that then I would use a for loop. The fgets will stop when the string it is reading is terminated. So just do this.
Code: Select all
FILE * textFile = fopen("filename.txt", "r");
int i;
for(i=0;i<150;i++)
{
    fgets(array[i], 255, textFile);
}
fclose(textFile);


You can't access the clipboard so you won't be able to copy things into a game, but you can simulate copy/paste within your game... but only in it.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Text strings

Postby Leif » Tue Aug 31, 2010 6:42 am

Ok
thanks a lot )
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron