[Solved]io.write() Issues

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Dr.Tyler O.
Citizen
Posts: 58
Joined: Tue Jul 29, 2014 9:17 am
Location: United States

[Solved]io.write() Issues

Post by Dr.Tyler O. »

First of all, I am aware this doesn't deal directly with love2d but I hope that can be overlooked. I am having issues with the io.write() function. When I attempt to call io.write() to an output file, the information is not written to the file until the application is closed. The program manages to generate the file but fails to insert the string. I have created an example to demonstrate this issue. I am also curious as to whether this is an issue with my computer as opposed to the code.
Attachments
WritingProblems.love
You might want to place this in a folder to avoid text document spam.
(1.49 KiB) Downloaded 101 times
Last edited by Dr.Tyler O. on Tue Aug 04, 2015 3:04 pm, edited 1 time in total.
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: io.write() Issues

Post by davisdude »

Try putting io.flush after io.write, that worked for me.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
Dr.Tyler O.
Citizen
Posts: 58
Joined: Tue Jul 29, 2014 9:17 am
Location: United States

Re: io.write() Issues

Post by Dr.Tyler O. »

davisdude wrote:Try putting io.flush after io.write, that worked for me.
Your solution works but I'm still curious, why do I need to close the file in order to write to it without closing the application?
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: io.write() Issues

Post by s-ol »

Dr.Tyler O. wrote:
davisdude wrote:Try putting io.flush after io.write, that worked for me.
Your solution works but I'm still curious, why do I need to close the file in order to write to it without closing the application?
Because if every time you want to write a single byte to a file, you would need to spin up the HDD, move the writing head into place etc. You would also need to wait for all other prior activity to stop. In order to speed things up there is a buffer system in place, so the actual changes live in the much faster RAM. The contents get flushed when the changes are larger than the buffer size, the application asks the OS to do so (by closing the file) or the application stops running.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests