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

Code Deleted Itself?

Started by applesauce10189, 04 March 2014 - 10:14 PM
applesauce10189 #1
Posted 04 March 2014 - 11:14 PM
I have absolutely no clue what happened, one second I was coding, then I went to test my code and it did nothing so I was just sitting there like "wtf? where's the menu and stuff I just coded?" I went to edit the code and it was blank! Thinking back on it, the program was labeled arcade, I also made a file with fs API and called it .arcade so I think I 100% cleared my entire program. Thank god I posted it on the forum so that's like a little backup. Here's the code I think caused it.


if not fs.exists("rom/.arcade") then
  local file = fs.open(".arcade", "w")
  file.writeLine("yes")
  file.close()
end

local file = fs.open(".arcade", "r")
check = file.readLine()
file.close()

If I'm right about accidentally wiping my program using that program then I truly am depressingly stupid.
Bomb Bloke #2
Posted 05 March 2014 - 12:15 AM
".arcade" isn't the same thing as "arcade", but you may've made a typo at some point. Opening a file in "w" mode indeed wipes the contents.

I do all my coding in an external editor, which may've avoided this issue - even if I manually wiped the file via ComputerCraft, I'd be able to simply switch windows and hit the "save" button again to dump it back onto the drive.

Also bear in mind that these days Windows automatically backs up some files for you (whether you have a dedicated backup drive or not). It's luck of the draw, but worth knowing about if you lose something again.
applesauce10189 #3
Posted 05 March 2014 - 04:31 AM
Thanks for the help Bomb Bloke, you said you do your coding in an external editor, if I were to make a program and edit it in notepad++ and after editing, could I go straight to the computer and run the code without exiting notepad++ and just change the code in notepad++ if I don't like the results? btw there was a previous version it seems, thanks for the tip on that :D/>
theoriginalbit #4
Posted 05 March 2014 - 04:43 AM
yes you can definitely edit the program in Notepad++ or any other similar text editor and then run the program in-game and it have the changes. Do note however any changes you make to the program will not be applied while it's running, you must stop and restart it for the changes to take effect.
apemanzilla #5
Posted 05 March 2014 - 04:48 AM
Thanks for the help Bomb Bloke, you said you do your coding in an external editor, if I were to make a program and edit it in notepad++ and after editing, could I go straight to the computer and run the code without exiting notepad++ and just change the code in notepad++ if I don't like the results? btw there was a previous version it seems, thanks for the tip on that :D/>/>
Run "id" on your computer and remember the number. Then open explorer and go to %appdata%/.minecraft/saves/<world name here>/computer/<the computer ID>. If you don't see a folder for the computer's ID, make one. Edit the files there and they will change in the computer.

Since CC doesn't add file extensions by default, you will need to either add them yourself or live with the ugly generic file icon and windows errors. I typically add the extensions to mine, it just means that you'll need to type "program.lua" instead of "program"
applesauce10189 #6
Posted 05 March 2014 - 04:49 AM
:D/> This is some really useful information for the future, thanks both Bomb Bloke and theoriginalbit :)/>