Jump to content




Basic file IO - Learn how to save data!

help lua

  • You cannot reply to this topic
46 replies to this topic

#21 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 23 September 2012 - 07:23 AM

I don't think you can edit/add anew part on a line, if that was what you ment.

#22 ben657

  • Members
  • 65 posts

Posted 23 September 2012 - 06:14 PM

View PostSariaz, on 23 September 2012 - 07:22 AM, said:

and so based of this I'm assuming that if i wanted more data id just do more write lines with the data or would it be like the write function and add to current line and if it dosnt is there anyway to append on to a previously written line besides reading it from file apending to it then rewriting old line?

Yeah, like with printing to the console, writeLine puts a line break at the end, and you can use file.Write to just append onto the current position. Hope that helps :P/>

#23 Sariaz

  • Members
  • 107 posts

Posted 24 September 2012 - 03:16 PM

yup thanks thats how i thought it would work but wanted to make sure before i started to count on that working like that.

#24 Mtdj2

  • Members
  • 66 posts
  • LocationBehind you

Posted 25 September 2012 - 02:26 PM

You could instead of the loop use;
tFile = file.readAll()
and acsess the first line like:
print(tFile[1])
Hope I helped... Well, I think I did.

#25 ben657

  • Members
  • 65 posts

Posted 25 September 2012 - 03:13 PM

View PostMtdj2, on 25 September 2012 - 02:26 PM, said:

You could instead of the loop use;
tFile = file.readAll()
and acsess the first line like:
print(tFile[1])
Hope I helped... Well, I think I did.

Oh that's how that works? honestly I've never used it, just sorta assumed it gives you the whole file as one string :P/>
Will add that into the OP ;)/>

#26 auser

  • New Members
  • 5 posts

Posted 30 September 2012 - 04:58 PM

How would you suggest extending this to a key=value store? (ini?)

#27 leftcatcher

  • Members
  • 28 posts

Posted 01 October 2012 - 10:44 AM

Just a few questions:

Does this program create more than one dispName and realName folder? Or does it just overwrite the previous one? Like, for example, I create the "leftcatcher" dispName and Blah for realName, and then I create "ben675" for dispName, and Blahblah for realName. Would there then be two folders in the "saves" section? One for each dispName? Or will the "leftcatcher" folder have been overwritten?

Could I get it to basically activate off a login? For example, on startup the computer will show a menu(Which I can set up easily) which says "Login" or "Create Account". We select the latter here and it starts up the program. It then ask for a Username, (which replaces the dispName here), and then asks for a Password (Replacing realName). It then basically just creates the file around he Username in the same way your program does around the dispName, and puts the Password into the file. Then, basically, in the "Login" section, it would ask for your Username and you would enter it, and it would access the file containing that username and make the Password = requiredPassword so that way you have to enter it to log in. Basically, what your program does but with a bit more added onto the ending. If your code here does in fact have the ability to create numerous folders, then it is entirely possible to have this and actually make use of it instead of it just being a one time thing. :<

#28 Doyle3694

  • Members
  • 815 posts

Posted 01 October 2012 - 03:20 PM

It is very possible. I have one made like 50% done, it works with logins and passwords but there are some things left to do like preventing double users wiht same username and stuff.
Spoiler


#29 leftcatcher

  • Members
  • 28 posts

Posted 01 October 2012 - 06:36 PM

Well, I figure you could use the fs.exists (I believe that's it) to check if the directory it's trying to save to already exists, and make it not do it if it does. This would happen if someone tried to create an account with the same name as someone else.

#30 Doyle3694

  • Members
  • 815 posts

Posted 02 October 2012 - 07:08 AM

not in my program. my program makes 1 file called 'users', 1 called 'passwords' and is going to in the future make 1 called 'rights'. and then it stores these in tables. But PM me if you need more information or help, don't want to spam down his thread.

#31 ben657

  • Members
  • 65 posts

Posted 02 October 2012 - 06:46 PM

View Postleftcatcher, on 01 October 2012 - 10:44 AM, said:

Just a few questions:

Does this program create more than one dispName and realName folder? Or does it just overwrite the previous one? Like, for example, I create the "leftcatcher" dispName and Blah for realName, and then I create "ben675" for dispName, and Blahblah for realName. Would there then be two folders in the "saves" section? One for each dispName? Or will the "leftcatcher" folder have been overwritten?

Could I get it to basically activate off a login? For example, on startup the computer will show a menu(Which I can set up easily) which says "Login" or "Create Account". We select the latter here and it starts up the program. It then ask for a Username, (which replaces the dispName here), and then asks for a Password (Replacing realName). It then basically just creates the file around he Username in the same way your program does around the dispName, and puts the Password into the file. Then, basically, in the "Login" section, it would ask for your Username and you would enter it, and it would access the file containing that username and make the Password = requiredPassword so that way you have to enter it to log in. Basically, what your program does but with a bit more added onto the ending. If your code here does in fact have the ability to create numerous folders, then it is entirely possible to have this and actually make use of it instead of it just being a one time thing. :<

Sounds like a good way of going about it :(/>
And yeah this code will work perfectly for that. Reason being, it makes a folder named saves, and in there are FILES not folders, with data in them, rather than more folders and FILES. But in short, yes. It'll work fine :D/>

#32 ben657

  • Members
  • 65 posts

Posted 02 October 2012 - 07:04 PM

View Postauser, on 30 September 2012 - 04:58 PM, said:

How would you suggest extending this to a key=value store? (ini?)

Very possible!
http://www.computerc...le-configs-v10/
Something I did a little while ago, all the codes there for it :(/>

#33 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 06 October 2012 - 02:52 AM

Thanks for this code! I need it to make my OS!

#34 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 07 October 2012 - 04:57 PM

Hmm. Mine works on a single pc. Where do the files save when making a file because mine isnt creating one :X

#35 pbcub1

  • New Members
  • 23 posts

Posted 08 October 2012 - 12:02 AM

i just want to say thank you for this tutorial because it has helped me in my development of a new Operating System i am in the middle of making

#36 ben657

  • Members
  • 65 posts

Posted 10 October 2012 - 11:15 AM

View Postsidekick_, on 07 October 2012 - 04:57 PM, said:

Hmm. Mine works on a single pc. Where do the files save when making a file because mine isnt creating one :X

Really? They should be in the folder you named in the file path during the tutorial. In game, load up the pc, do "ls" (no quotes), see of there's a new folder and do "cd thatfoldersname", then ls again to see if your files there.

#37 Frederikam

  • Members
  • 112 posts
  • LocationDenmark

Posted 29 December 2012 - 12:25 AM

This really is useful, just what I needed. I can see myself doing tons of turtles that uses this code.

#38 AnthonyD98™

  • Members
  • 193 posts
  • LocationAuckland, New Zealand

Posted 31 January 2013 - 06:59 PM

Nice Tutorial :)

#39 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 05 February 2013 - 11:07 AM

Well Thanks For The Tutorial, It was Great! :D
Now I've finally added the ability to save/load/delete in my Game that's in my sig.
But it's in an unreleased version.
But anyway thx so much!

#40 ThatNewb

  • Members
  • 7 posts

Posted 12 March 2013 - 09:28 AM

nice tutorial





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users