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

This forum is currently in read-only mode.
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • 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:

    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!
  • 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...

    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
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This is also doable with events:

    http://dl.dropbox.com/u/5426011/examples/append2.cap

    req 0.99.84

    + 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]
  • This is also doable with events:

    http://dl.dropbox.com/u/5426011/examples/append2.cap

    req 0.99.84

    + 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]
    

    That's good to know

    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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)