Author Topic: Writing to files  (Read 2488 times)

gaulthunter

  • Newcomer
  • *
  • Posts: 9
    • View Profile
Writing to files
« on: 09. February 2013, 01:57:53 »
Hello, I've been using EGSL (I like to call it eggshell) for a while, and noticed when porting one of my lua programs, that it seems to lack (Or I haven't noticed) a system to write or read from files... How can this be achieved?

kolyamatic

  • Newcomer
  • *
  • Posts: 18
    • View Profile
Re: Writing to files
« Reply #1 on: 09. February 2013, 07:59:29 »
Firstly, I might say that "eggshell" sounds like a rather funny name for EGSL.

Other than that, Eggshell does not lack a way of doing such things. Though, the resource upon which one could achieve the knowledge of how to doing this, is not quite finished yet.
Anyway, this link (which redirects to the, as mentioned before, unfinished documentation) should help you at least a little:
http://egsl.retrogamecoding.org/documentation/egsldocumentation.html
I hope that this forum supports link-posting.
If not so, just search for the documentation or ask someone round here.

Additionally, I may try some of the commands in the next few days, as I literally rush through the unexplained commands by (attempting to) using them in programmes.


-- Kolyamatic
-- EDIT: some minor grammatical issues

Tomaaz

  • Guest
Re: Writing to files
« Reply #2 on: 09. February 2013, 15:39:25 »
EGSL can do everything Lua can, so you can simply use Lua functions for working with files. You can also use additional EGSL functions - see File Management section in EGSL documentation.

cvirus

  • Regular Member
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Re: Writing to files
« Reply #3 on: 09. February 2013, 19:54:28 »
Simple example to write into a file using LUA.

Code: [Select]
local file = io.open("text.txt", "w")
file:write("writing to text.txt file with EGSL and LUA")
file:flush()
file:close()

The "w" means you can write and you can use others such "a" for appending.

for further reading http://www.lua.org/pil/21.1.html

« Last Edit: 09. February 2013, 19:58:27 by cvirus »

Tomaaz

  • Guest
Re: Writing to files
« Reply #4 on: 09. February 2013, 20:05:20 »
And this is how it looks with additional EGSL function:

Code: [Select]
a = open("test2.txt", "w")
fprint(a, "Writing to text.txt file with EGSL and LUA")
close(a)

lelldorin

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • BeSly - Knowledge base
Re: Writing to files
« Reply #5 on: 09. February 2013, 23:03:03 »
And this is how it looks with additional EGSL function:

Code: [Select]
a = open("test2.txt", "w")
fprint(a, "Writing to text.txt file with EGSL and LUA")
close(a)

Nice, and with variables?

its for the templates odf my EGSL IDE

Can you explaint reading from file too :-)

Tomaaz

  • Guest
Re: Writing to files
« Reply #6 on: 10. February 2013, 13:12:58 »
Here is example that creates test.txt file and writes numbers from 1 to 10 to it. Every time you run it again, it add next ten numbers to the file.

Code: [Select]
if (fileexists("test.txt") == false) then
plik = open("test.txt", "w")
for x = 1, 10 do
fprint(plik, x)
end
close(plik)
end

plik = open("test.txt", "r")
x = 0
while (eof(plik) == false) do
x = x + 1
finput(plik)
end
close(plik)

plik = open("test.txt", "a")
for y = x + 1, x + 10 do
fprint(plik, y)
end
close(plik)

lelldorin

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • BeSly - Knowledge base
Re: Writing to files
« Reply #7 on: 10. February 2013, 15:55:29 »
For my templates of my EGSL IDE is this too much. I need smal ones, like onle read file or only read folder reoutines.

I have open a new treat for this, because i will collect all i can get :-)

*Sorry bad english ;-)

gaulthunter

  • Newcomer
  • *
  • Posts: 9
    • View Profile
Re: Writing to files
« Reply #8 on: 18. February 2013, 04:47:54 »
Firstly, I might say that "eggshell" sounds like a rather funny name for EGSL.

Other than that, Eggshell does not lack a way of doing such things. Though, the resource upon which one could achieve the knowledge of how to doing this, is not quite finished yet.
Anyway, this link (which redirects to the, as mentioned before, unfinished documentation) should help you at least a little:
http://egsl.retrogamecoding.org/documentation/egsldocumentation.html
I hope that this forum supports link-posting.
If not so, just search for the documentation or ask someone round here.

Additionally, I may try some of the commands in the next few days, as I literally rush through the unexplained commands by (attempting to) using them in programmes.


-- Kolyamatic
-- EDIT: some minor grammatical issues

I've read that and used the functions it has listed, they create the files, as I want, but don't seem to write or read from them.

gaulthunter

  • Newcomer
  • *
  • Posts: 9
    • View Profile
Re: Writing to files
« Reply #9 on: 18. February 2013, 04:48:47 »
EGSL can do everything Lua can, so you can simply use Lua functions for working with files. You can also use additional EGSL functions - see File Management section in EGSL documentation.
When I use the default Lua syntax, it raises an error in the Eggshell IDE...

gaulthunter

  • Newcomer
  • *
  • Posts: 9
    • View Profile
Re: Writing to files
« Reply #10 on: 18. February 2013, 04:50:11 »
Let me give it another try, an example someone gave has given me an idea

gaulthunter

  • Newcomer
  • *
  • Posts: 9
    • View Profile
Re: Writing to files
« Reply #11 on: 18. February 2013, 05:02:13 »
I got it working! Thank you to everyone!