Saving text to a *.txt file (Found Python Solution)

For questions about using Classic.

Post » Sun Apr 04, 2010 2:44 pm

I just finished creating a GUI dialogue creator for my game which exports the text I input into edit boxes into the appropriate format readable by my game (e.g "NPC"=['dialogue1','dialogue2'] ).

Right now I can simply copy and paste it into the text file, but I was wondering if there was any way to paste the output of an 'edit box' to the end of a *.txt document. I've tried INI and TextManipulator, and it worked with INI. But the problem is, it does not work with multiline edit boxes.

A small example of what I want.

Output generated:
NPC =
"Hello I'm awesome"
"And so are you!"

Click 'Save'


Updated Text File:
[code:3jwp20ya]
Player =
"Bla"
"Blabla bla... bla"

Char =
"Melbourne >> Sydney"

NPC =
"Hello I'm awesome"
"And so are you!"
[/code:3jwp20ya]

Something that does that! I'm thinking it's possible with Python and I'm currently researching into it, but I want to know if it's possible without.

Thanks in advance!
B
2
S
2
G
3
Posts: 143
Reputation: 1,536

Post » Sun Apr 04, 2010 3:06 pm

Wow, found a Python solution which is so damn simple. I was hoping for an event sheet solution because I thought it'd be too complicated in Python but all you need is...

[code:wifmxk2a]x = open('dialogue.txt', 'a')
x.write("\n")
x.write(Name.Text + " :\n\n" )
x.write('"' + Dial.Text + '"' + "\n")
x.close()[/code:wifmxk2a]

A bit of testing, this is the result:

[code:wifmxk2a]
Shady :

"I love Python!"

Homer :

"Don't you hate pants?"

Joe :

"I'm a plumber!"

Supports.... :

"Multiline!
Right?
...

Guess so :)"

[/code:wifmxk2a]

Was going to delete the thread, but I guess it's better to have this as reference for anyone in the future wanting to do something similar.

Python, my new found love :wink:
B
2
S
2
G
3
Posts: 143
Reputation: 1,536

Post » Mon Apr 05, 2010 3:50 am

This is also doable with events:

[url:2lq13ftb]http://dl.dropbox.com/u/5426011/examples/append2.cap[/url:2lq13ftb]
req 0.99.84

[code:2lq13ftb]+ Button: On Button clicked
+ File: File "dialog.txt" exists
-> EditBox: Load file "dialog.txt"
+ System: Always (every tick)
-> EditBox: Append text NewLine
-> EditBox: Append text Name.Text & " :"&NewLine&NewLine
-> EditBox: Append text """"&Dial.Text&""""&NewLine
-> EditBox: Save file "dialog.txt"[/code:2lq13ftb]
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Mon Apr 05, 2010 4:16 am

[quote="R0J0hound":1ez2el68]This is also doable with events:

[url:1ez2el68]http://dl.dropbox.com/u/5426011/examples/append2.cap[/url:1ez2el68]
req 0.99.84

[code:1ez2el68]+ Button: On Button clicked
+ File: File "dialog.txt" exists
-> EditBox: Load file "dialog.txt"
+ System: Always (every tick)
-> EditBox: Append text NewLine
-> EditBox: Append text Name.Text & " :"&NewLine&NewLine
-> EditBox: Append text """"&Dial.Text&""""&NewLine
-> EditBox: Save file "dialog.txt"[/code:1ez2el68][/quote:1ez2el68]
That's good to know :D

Though I think I'll stick with the Python solution since it's very simple! I should really try to use more of Python in construct, since i did recently start learning it in University. Will be a good way to put my skills to the test.

Thanks R0J0hound!
B
2
S
2
G
3
Posts: 143
Reputation: 1,536


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests