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

Save values on restart

Started by Stroooomdahl, 25 February 2014 - 12:06 PM
Stroooomdahl #1
Posted 25 February 2014 - 01:06 PM
Hello!

I couldn't find a thread about this…

I got an idea for a program that will count the number of items my mob spawner drops but the problem is that it will not save the value when i shut down minecraft..
Is there a way to make the computer to remember the value after a restart has been done?

Ps Im sorry if their is some miss spelling or false grammar. i'm from sweden so my english is not that good.
wieselkatze #2
Posted 25 February 2014 - 01:36 PM
You could just store them in actual files and load them after restart; that should be the easiest way.

For example your count is "count" and equals 10.
Then you could store this in a file:


count = 10
f = fs.open("mobspawn", "w")
f.writeLine(count)
f.close()

at the top op the program you just have to put


f = fs.open("mobspawn", "r")
count = tonumber(f.readLine())
f.close()

That should be it. (Not tested)
DannySMc #3
Posted 25 February 2014 - 11:26 PM
You could use an config file…. I have an API that you're welcome to use, the syntax is:

os.loadAPI("uapi")
-- intCount being the number of drops
uapi.saveConfig({['count']=intCount}, ".config") -- will save it
-- on boot use:
local config = uapi.loadConfig(".Config")
count = config.count

then use count as the number, you can make it write the new number every time (using loops, or add it as part of a function/corountine)

To get it use the retriever (use the following command in terminal):

pastebin get rTDR0tjx uretrieve

then run it by typing 'uretrieve' (without quotes)

Post:
http://www.computercraft.info/forums2/index.php?/topic/16021-uprograms/page__fromsearch__1

Hope this helps!
Danny!
Edited on 25 February 2014 - 10:28 PM