This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Svetlack's profile picture

[Lua] [Question] Saving variables in a (text) file?

Started by Svetlack, 18 September 2012 - 01:13 AM
Svetlack #1
Posted 18 September 2012 - 03:13 AM
So, I know that this is probably asked a lot, but I've tried to figure it out and really can't. I've looked over the fs api help screen, and truly can't for the life of me figure out how to do what I want to do.

I'm running CC 1.41 on a 1.2.5 server. It's mine, so I can access the files if need be.
Really have like, no code done because I got stuck here, but I could paste what I have or whatever if it's important for some reason I can't see. Just a clearing function and the variable list.


So, this is what I'm trying to get done:

"Banking" system: Have the "cashier" open a program.
Prompt for Customer's user number, read() saved into a variable for that.
if userName == 0001 (or whatever) then
if password == "whatever" then
open a file and find the account balance
else
clear, stop program.
elseif userName == 0002

… You get the idea.
Basically, I know I want a way to save a numeric variable, say a "program" file, which could be read and then give the account balance. The main reason I'd like to do it this way is because I have to reset my server sometimes, and I'd have no way of knowing where the balance was. Not that it's going to be used crazy amounts or whatever, I'd just like to have it prim and proper. Just because.

So anyway, anything else I need to type/paste/inform you guys on or whatever, I can/ I think I covered it all. Thanks. :)/>/>


I'm an idiot. Disregard.
Maome #2
Posted 18 September 2012 - 04:19 AM
As always try to help yourself with something like this great resource and hopefully you'll end up somewhere like here. That should get you started on file io as it seems like you can already find your way through the password setup.
Svetlack #3
Posted 18 September 2012 - 06:33 AM
Hi!

Wow, I'm stupid. I completely missed that, for some reason.
I have no idea what I tried to google, but it must have been retarded for some reason.

Anyway, sorry about this. I'll go die in a corner now.

o-o
Maome #4
Posted 18 September 2012 - 07:45 AM
:)/>/> hey don't be afraid to ask questions after you try to get some code down.