Page 1 of 1
.txt files
Posted:
Sun Dec 04, 2011 10:32 am
by themasterX
does anyone know how to be able to type text and so it goes to a separate .txt file?
+1 to first decent answer
Re: .txt files
Posted:
Sun Dec 04, 2011 3:46 pm
by DarkParadox
Have your text actor (created by making an actor, in this example assumed myactor, and going into text and setting it to enable input), and on whatever event you feel like having trigger the save (it could even be on any keypress, if you wanted it to save whenever you type) and use the code (replace "myactor" with the actor you have the text you want to save..)
- Code: Select all
FILE*file;
file = fopen("TextNote.txt", "w+");
fwrite(&myactor.text, sizeof(myactor.text), 1, file);
fclose(file);
(I snatched this code from another thread, don't know if it works, but it should.. just say if it doesn't)
Re: .txt files
Posted:
Mon Dec 05, 2011 12:19 am
by themasterX
could you explain that
Re: .txt files
Posted:
Mon Dec 05, 2011 1:58 am
by DarkParadox
Er, okay. I'll go step-by-step here.
- Make a new actor, name it (for this example, TextSaver).
- Click on our new actor (if the actor panel is already open, if not, right click the actor and select "Actor Control")
- Click the text button, top right of the menu, and switch the "Text Input" Setting to yes, and type a word or two in the text area (without it, the text box will have no size. You can change the boxes appearance in the Config menu, and make sure to choose a font.)
- Close out of that menu, and click Events->Add->Mouse Button Down
- Click the right mouse button, and do Add Action->Script Editor
- Put this code in the text area,
- Code: Select all
FILE*file;
file = fopen("TextNote.txt", "w+");
fwrite(&TextSaver.text, sizeof(TextSaver.text), 1, file);
fclose(file);
And Add-> Immediate Action - Close out of those menus, and tada, in Game Mode when you right-click on our textbox, it will save the text in the box to "TextNote.txt".
- You can change the actors name in the script and the name of the text file..
- Make sure to remember, you can put that script on any even, doesn't have to be a mouse down. You can have the user click a button, or on every keypress.
- Hope this is right...
Re: .txt files
Posted:
Mon Dec 05, 2011 2:30 am
by themasterX
is it possible to be able to name the file from the export and can you make multiple files?
Re: .txt files
Posted:
Tue Dec 06, 2011 12:20 am
by SuperSonic
themasterX wrote:is it possible to be able to name the file from the export and can you make multiple files?
If you want to change the name of the .txt file, just change the part that says
TextNote.txt to whatever name you want
@DarkParadox: Hey man, I thought you left. Welcome back
BTW: I still have that Eros theme on my computer (it's finished). Do you still want it?
Re: .txt files
Posted:
Tue Dec 06, 2011 3:44 am
by DarkParadox
@SuperSonic: Pshaw, I still lurk around here every now and then, every other day or so. I'll answer questions if there aren't any replies in the topic, but you guys are really fast so I don't get much chances ヽ(゚ロ゚;)
And might as well take that theme since you worked on it, thanks!
Oh and... the chat booox, whyyyy. I loved that thing. Now... (・‸・)
Re: .txt files
Posted:
Tue Dec 06, 2011 5:18 am
by themasterX
SuperSonic wrote:themasterX wrote:is it possible to be able to name the file from the export and can you make multiple files?
If you want to change the name of the .txt file, just change the part that says
TextNote.txt to whatever name you want
no, what i mean is can you change it in-game
so the player can name the file
Re: .txt files
Posted:
Tue Dec 06, 2011 6:06 am
by skydereign
Yeah, you can use the rename function. It's one of the few functions that gE can use that isn't on the script reference.
- Code: Select all
rename("old_name", "new_name");
Re: .txt files
Posted:
Tue Dec 06, 2011 6:37 am
by themasterX
is there a function that allows you to create a new file?
sorry for my dumb questions
Re: .txt files
Posted:
Tue Dec 06, 2011 7:41 am
by skydereign
Well, if you just wanted to create a file, you can use fopen like in DarkParadox's example fopen can be used to create, write into, and read files, by way of FILE*s.
Re: .txt files
Posted:
Tue Dec 06, 2011 8:07 am
by lcl
Hey skydereign, could you tell me a little more of that rename() function?
What is it for? Also how many more of these "hidden" functions there are?
Re: .txt files
Posted:
Tue Dec 06, 2011 8:24 am
by skydereign
There aren't many, but I think there are at least two more (though I can't remember what they were offhand). The functions were just some of C's standard library functions, but since gE doesn't allow deleting of files, makslane removed those functions, although this one was left. All rename does is rename a file. It will return a 0 if the rename was successful, and a non-zero if it fails. The only times I'd use it is if you use publicly viewable files. So, if you had a save file given a characters name, you might rename the file if you change the name of the character. Other than that though... it doesn't let you rename files to a preexisting filename, meaning it can't act as remove does.
Re: .txt files
Posted:
Tue Dec 06, 2011 1:48 pm
by SuperSonic
DarkParadox wrote:@SuperSonic: Pshaw, I still lurk around here every now and then, every other day or so. I'll answer questions if there aren't any replies in the topic, but you guys are really fast so I don't get much chances ヽ(゚ロ゚;)
Well it's great to know that you're not gone
I'll send you a PM with the Eros theme in it. Just as soon as I can upload it^^@Sky: Wow, that's so cool. I never knew that there were other functions like that
Re: .txt files
Posted:
Wed Jul 02, 2014 9:47 pm
by JoeLopez
Hi folks. My game keeps crashing when I run this code. "TextSaver" is a text actor. Can anyone help?
- Code: Select all
FILE*file;
file = fopen("TextNote.txt", "w+");
fwrite(&TextSaver.text, sizeof(TextSaver.text), 1, file);
fclose(file);