.txt files

Game Editor comments and discussion.

.txt files

Postby themasterX » Sun Dec 04, 2011 10:32 am

does anyone know how to be able to type text and so it goes to a separate .txt file?
+1 to first decent answer
User avatar
themasterX
 
Posts: 5
Joined: Sat Dec 03, 2011 8:16 am
Score: 0 Give a positive score

Re: .txt files

Postby DarkParadox » Sun Dec 04, 2011 3:46 pm

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)
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: .txt files

Postby themasterX » Mon Dec 05, 2011 12:19 am

could you explain that
User avatar
themasterX
 
Posts: 5
Joined: Sat Dec 03, 2011 8:16 am
Score: 0 Give a positive score

Re: .txt files

Postby DarkParadox » Mon Dec 05, 2011 1:58 am

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...
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: .txt files

Postby themasterX » Mon Dec 05, 2011 2:30 am

is it possible to be able to name the file from the export and can you make multiple files?
User avatar
themasterX
 
Posts: 5
Joined: Sat Dec 03, 2011 8:16 am
Score: 0 Give a positive score

Re: .txt files

Postby SuperSonic » Tue Dec 06, 2011 12:20 am

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 :D

@DarkParadox: Hey man, I thought you left. Welcome back :P
BTW: I still have that Eros theme on my computer (it's finished). Do you still want it?
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: .txt files

Postby DarkParadox » Tue Dec 06, 2011 3:44 am

@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...
(・‸・)
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: .txt files

Postby themasterX » Tue Dec 06, 2011 5:18 am

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 :D
no, what i mean is can you change it in-game
so the player can name the file
User avatar
themasterX
 
Posts: 5
Joined: Sat Dec 03, 2011 8:16 am
Score: 0 Give a positive score

Re: .txt files

Postby skydereign » Tue Dec 06, 2011 6:06 am

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");
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: .txt files

Postby themasterX » Tue Dec 06, 2011 6:37 am

is there a function that allows you to create a new file?
sorry for my dumb questions
User avatar
themasterX
 
Posts: 5
Joined: Sat Dec 03, 2011 8:16 am
Score: 0 Give a positive score

Re: .txt files

Postby skydereign » Tue Dec 06, 2011 7:41 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: .txt files

Postby lcl » Tue Dec 06, 2011 8:07 am

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?
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: .txt files

Postby skydereign » Tue Dec 06, 2011 8:24 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: .txt files

Postby SuperSonic » Tue Dec 06, 2011 1:48 pm

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 :P
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 :D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: .txt files

Postby JoeLopez » Wed Jul 02, 2014 9:47 pm

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);
JoeLopez
 
Posts: 4
Joined: Fri May 02, 2014 1:47 am
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest