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

Program modifying config file

Started by artman41, 07 April 2015 - 12:14 PM
artman41 #1
Posted 07 April 2015 - 02:14 PM
The problem is in my startup file which can be found here: http://pastebin.com/2zpMmLs2

—–

I have an IF statement check to see if a file exists and every time I run the program, if it doesn't detect the file, it creates a new one with the string "drives" in it. Now, this works. Then I check to see if there are arguments and, if there are, rewrite the config file to contain the argument passed instead.

However, if I don't give any arguments, the program will rewrite the config file to contain the string "drives", which makes me think that it's re-running through the original IF statement since I'm not modifying the config file else where. However, when I put a print() function in the IF statement, it doesn't call the function but still modifies the config file, which confuses me.

—–

If you want to try the program as I am, here's a pastebin for an installer: http://pastebin.comDVKnYWjY

If anyone could explain why the program's modifying the config file, that'd be great :D/>
Edited on 07 April 2015 - 12:15 PM
apemanzilla #2
Posted 07 April 2015 - 02:20 PM
You're doing "if fs.exists(…) then". This means that the code will only run if the file exists. It sounds like you want the opposite, so change line 3 to:

if not fs.exists("config/start.cfg") then

Edit: Also, instead of using table.getn(args) you can also just use #args. It's more compact.
Edited on 07 April 2015 - 12:21 PM
artman41 #3
Posted 07 April 2015 - 02:21 PM
You're doing "if fs.exists(…) then". This means that the code will only run if the file exists. It sounds like you want the opposite, so change line 3 to:

if not fs.exists("config/start.cfg") then

Edit: Also, instead of using table.getn(args) you can also just use #args. It's more compact.

Thank you :D/> This got it working perfectly, and I'll most likely use your tip with #args