Jump to content


Zepate's Content

There have been 3 items by Zepate (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#277513 [N00b] - Trouble using IO library

Posted by Zepate on 04 June 2018 - 09:28 AM in Ask a Pro

io is more flexible since it let's you chose the of the characrter of end of line. FS library is made on top of IO so it make sens for me to say io is more flexible but it's my opinion



#277502 [N00b] - Trouble using IO library

Posted by Zepate on 01 June 2018 - 02:36 PM in Ask a Pro

Thanks a lot but you will hate me since i found the solution before the approval of the modo 😬 :grimacing:

I think the Wiki must be updated since:
  • there is no tutorial on how to write files from lua in CC
  • the IO api is not enought documented
  • the use of fs api provide missleading coding style with IO api (note the notation "." and ":" for the same purpose)
So if somone have the same issue than me i advise you to do the following.

you want to write some strings to a file. To do so you have 2 option:
  • the hard way but more flexible way is to use IO library
  • the quick and dirty yet powerfull way is to use FS library (CC endemic not sure if it is CraftOS endemic)
What you have to do is to create a file handle that ack like C type file handle:
Myownfile = io.open("myfile.txt","w")
Myownfile.write(Myownfile,"This is the first thing in my file")
Myownfile.close(Myownfile)
This code should do the trick but you can use less verbose and more efficient? notation
f = io.open("text_file.txt","w")
f:write("this is a test")
f:close()

Note the diference between dot notation "." and semicolon ":"

Thanks bomb bloke for your help !

I made a long post and i sure that i left some misspelling since english isn't my native language so if you notice something that hurt your eyes tell me i'll edit



#277496 [N00b] - Trouble using IO library

Posted by Zepate on 01 June 2018 - 12:47 PM in Ask a Pro

Hello, i'm new to this forum and I am nice to meet you all.

I have trouble in creating files that i can read with CraftOS. For some reason I can write whatever i want without error but nothing is writen in the intented file.

to begin i use:
  • minecraft 1.12.2
  • MCP (coderpack) 9.19
  • Forge 14.21.1
  • chicken chunk 2.4.1.71
and
  • CC 1.80 pr1
What I did:
  • Build computer, and start it by right clicking then:
Posted Image
https://pasteboard.co/HnSwNkY.png

if i go back to craft os i have the folowing:
Posted Image
https://pasteboard.co/HnSxrAS.png

If i edit the test.txt with "edit test.txt" nothing is inside the file

Can someone help me please :)