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

Saving a .lua file with variables

Started by TheNotch3000, 06 May 2012 - 04:31 PM
TheNotch3000 #1
Posted 06 May 2012 - 06:31 PM
[Lua][Question](Sorry for not adding tags in title)
How can I make a .lua file anywhere on my harddisk. I have my code to make a .lua file and write to it, but I need te be able to save/read it from anywhere on the harddisk.

local file = io.open("/test.lua", "w")
file:write("Hello!")
file:close()
(so instead of saving it to where its run from, I want to save it to C:/Computercraft/test.lua. But when I try that it does nothing, neither throw an error)
Hawk777 #2
Posted 06 May 2012 - 06:54 PM
This would be a terrible idea for security, particularly on multiplayer servers but also if you ever downloaded a world from someone else to try out. ComputerCraft computers can only see/create files in their own directory (minecraft/saves/yourworld/computer/compid) or in the directories of attached disks (minecraft/saves/yourworld/computer/disk/diskid).
TheNotch3000 #3
Posted 06 May 2012 - 06:57 PM
That sounds logical. Thanks for the answer.
Dirkus7 #4
Posted 06 May 2012 - 10:09 PM
Try the network peripheral, it does exactly what you want. It makes a shared folder somewhere on your hard disk, which al computers can use. You can find it in the peripheral library.
TheNotch3000 #5
Posted 07 May 2012 - 07:11 AM
I like that network peripheral, but I don't like everyone on my server to download it. Isn't it possible to an api(because all computers share them), store variables in it, and read/write them?
Hawk777 #6
Posted 07 May 2012 - 05:57 PM
Unfortunately no. Although the code for an API is shared (it's stored in mods/ComputerCraft/lua/rom/apis), the running environment of an API is specific to the computer it's running on, just like any other code.