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

[1.41]State saving (a small help)

Started by Sebra, 11 August 2012 - 01:52 PM
Sebra #1
Posted 11 August 2012 - 03:52 PM
Hi! It was a long time I was not here. CC made a big leap but still not perfect ;)/>/>

I want a Turtle to keep several values through save/load. I know it keep power state now. I think it keep PowerLevel too. More of this I know how to make Turtle to store and load values to/from disk file. But in my opinion it is not good to rewrite a file on each step. Also I want a way to forbid certain Computer to ignore Disks on startup. So my suggestion:

Add some "hardware" table to Computers, which:
1.restricted to store only numbers; (as strings are variable length)
2.restricted in number; (and have predefined names)
3.saved/loaded with the chunk save/loading;
4.defaulted as 0 when Computer crafted;
5.one value forbid Drive reading on startup if changed.

I want to store calculated coords in them and also current Turtle status. May be someone else would use it for something else.
Tiin57 #2
Posted 11 August 2012 - 04:00 PM
I can't really understand the question, as it's worded strangely (Second language? No worries.) but can't you already do this by using the fs api to store data and open it back up? Such as save data for an excavation program.
Sebra #3
Posted 11 August 2012 - 06:41 PM
I know how to make Turtle to store and load values to/from disk file. But in my opinion it is not good to rewrite a file on each step.
Yes, my native language is not latin.
dimitriye98 #4
Posted 12 August 2012 - 06:08 AM
Yes, my native language is not latin.
You mean english right? :P/>/> We don't speak latin… Well, at least I don't.
Pharap #5
Posted 12 August 2012 - 07:46 AM
Hi! It was a long time I was not here. CC made a big leap but still not perfect :P/>/>

I want a Turtle to keep several values through save/load. I know it keep power state now. I think it keep PowerLevel too. More of this I know how to make Turtle to store and load values to/from disk file. But in my opinion it is not good to rewrite a file on each step. Also I want a way to forbid certain Computer to ignore Disks on startup. So my suggestion:

Add some "hardware" table to Computers, which:
1.restricted to store only numbers; (as strings are variable length)
2.restricted in number; (and have predefined names)
3.saved/loaded with the chunk save/loading;
4.defaulted as 0 when Computer crafted;
5.one value forbid Drive reading on startup if changed.

I want to store calculated coords in them and also current Turtle status. May be someone else would use it for something else.

The issue is that when a file is saved in CC, it is saved as an actual file in your computer, thus the data is basic text (string data). Auto-parsing could be implemented, but it's not always what people want.


I agree about disk drives though, it's annoying that the overwrite the computer's startup, either the disk should be made second or both startup programs should run, with the computer's startup having priority.
Sebra #6
Posted 12 August 2012 - 09:59 AM
I mean not latin based.

If I understand right, on chank save Computer stored as a structure with some data. I want several values to be stored in that structure. Only several and only numbers to limit size. Startup autorun flag for bios to support protection. Without external startup file and assigned label stored data cannot be accessed and can be destroyed only.
Pharap #7
Posted 12 August 2012 - 10:58 AM
I mean not latin based.

If I understand right, on chank save Computer stored as a structure with some data. I want several values to be stored in that structure. Only several and only numbers to limit size. Startup autorun flag for bios to support protection. Without external startup file and assigned label stored data cannot be accessed and can be destroyed only.

Sounds like your best option is to write data to an external disk, then eject and remove the data so it can't be used by other people.
If you store your program and the save files on a disk, it would stop people messing with it since you could carry it around with you.
There are several different threads around the forums about how to use the file saving features, so I'm sure you could adapt them by loading them into a table, line by line.
Sebra #8
Posted 12 August 2012 - 11:16 AM
Sounds like you cannot understand me or I cannot explain it to you.
Imagine a Computer running unknown program. Think about password door, tree farm, processing factory or spying satellite.
You want to read this program but Computer would not allow you.
You place a Drive with startup file but it refuse to start from it.
You broke Computer but without label disk data completely lost.
Pharap #9
Posted 12 August 2012 - 11:26 AM
Sounds like you cannot understand me or I cannot explain it to you.
Imagine a Computer running unknown program. Think about password door, tree farm, processing factory or spying satellite.
You want to read this program but Computer would not allow you.
You place a Drive with startup file but it refuse to start from it.
You broke Computer but without label disk data completely lost.

A computer stopping you reading a file would be easy enough with a login system or hidden disk drive where the disk stores the programs you don't want someone to read and ejects it when someone other than the admin logs in.

It's pretty much widely known/accepted that disk startup files get priority over computer ones and there's no way of changing it.

If you make a program called 'backup' that copies every file in the computer to a disk, you won't have to worry about the computer being destroyed since it will all be backed up on a disk. (there's also a way to cheat by moving around files in the world save data, but you can't do that on a server)
Tiin57 #10
Posted 12 August 2012 - 12:02 PM
Actually, I believe EpicCoderz has figured out a way to force the disks out before they start up (though he may have modified the global bios). It's honestly one hell of a bit of malware.
Pharap #11
Posted 12 August 2012 - 03:09 PM
Actually, I believe EpicCoderz has figured out a way to force the disks out before they start up (though he may have modified the global bios). It's honestly one hell of a bit of malware.

Probably modified the bios, which is no use in a server you don't own.
dimitriye98 #12
Posted 12 August 2012 - 10:30 PM
He didn't modify the bios. "bios.lua" actually has nothing to do with the startup file. The startup file is detected and run by the shell.
Pharap #13
Posted 12 August 2012 - 11:43 PM
He didn't modify the bios. "bios.lua" actually has nothing to do with the startup file. The startup file is detected and run by the shell.
]

Either way it's done by editing files.
And bios.lua can affect startup if you want it to.
dimitriye98 #14
Posted 14 August 2012 - 04:13 AM
Either way it's done by editing files.
And bios.lua can affect startup if you want it to.

Yes it can, but it doesn't. It's important to make the distinction between the shell and the bios because the shell is a program that can be run even after startup while bios only activates when the computer is started.
Cranium #15
Posted 14 August 2012 - 05:33 PM
Even a basic "resume" feature would be nice. If a computer could resume from where it left off if it gets unloaded, or the world is shut off, it would be nice to know that it will keep that state when you come back to it. If I have a turtle building a huge structure, and leave to do something else, and come back later, I want it to keep going without me telling it to start over since it unloaded.
EDIT: Now that I think of it, this moght not be as simple as I think…
Pharap #16
Posted 14 August 2012 - 06:07 PM
Even a basic "resume" feature would be nice. If a computer could resume from where it left off if it gets unloaded, or the world is shut off, it would be nice to know that it will keep that state when you come back to it. If I have a turtle building a huge structure, and leave to do something else, and come back later, I want it to keep going without me telling it to start over since it unloaded.
EDIT: Now that I think of it, this moght not be as simple as I think…

It's possible, it's just complicated and would either require a load state feature added to the program or modifications to the OS. If there's a way to grab the program termination event (which I think there is) that would make things easier. Generally though, it would require mimicking what mos OSes do - shoving a load of data into temp memory and prompting the user to recover it upon startup. Again, not going to be very advanced without making a new OS.

If you handle it like a game though and have a save/load feature, you can do it that way and by using a bit of flim-flammery to force the program to skip some loops, processes and conditions and shove you straight back to where you were in the program. It would add a lot more code though.
Cranium #17
Posted 14 August 2012 - 06:16 PM
Making a new OS? No thank you…
Pharap #18
Posted 14 August 2012 - 06:26 PM
Making a new OS? No thank you…

Again, it depends what exactly you're trying to do it for. If it's for your master control system, that should be doable.

Which reminds me, when I tried your code, I couldn't reproduce the error you got, but I did find and fix 3 other errors, and I think I've located a few unintended things/possible errors, so be sure to contact me when you get chance.