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

Attempt to call string.

Started by cheekycharlie101, 08 December 2012 - 06:29 AM
cheekycharlie101 #1
Posted 08 December 2012 - 07:29 AM
ok so i have this code:

local path = "entrys"
term.clear()
term.setCursorPos(1,1)
print("Please enter an entry name...")
write("Name: ")
local name = io.read()
local exist = fs.exists(path "/", name)
if exist then
  print("Entry Already Exists.")
else
print("Entry Ok")

as im sure you can work out, you enter a name then it goes and checks to see if it exists in the entrys folder. if it does it prints:
entry already exists
if it does not exist it prints:
Entry Ok.
but i get an error on the IF statment line saying
"attempt to call string".
i think there is a problem with the exist varible but cant work out what it is?
can anyone help me out a little?
thanks -Cheeky
Doyle3694 #2
Posted 08 December 2012 - 07:36 AM
first, your last if statement lacks a end.

second, fs.exists(path.."/"..name)

My suspision is that it should be a \ instead, too, but Im not that good with fs directories, so someone experienced would have to confirm

EDIT: Checked wiki, I was wrong, it should be a /
Bubba #3
Posted 08 December 2012 - 07:41 AM
first, your last if statement lacks a end.

second, fs.exists(path.."/"..name)

My suspision is that it should be a \ instead, too, but Im not that good with fs directories, so someone experienced would have to confirm

EDIT: Checked wiki, I was wrong, it should be a /

I know that you already said this, but I am just clarifying for the OP.

fs.exists(path "/", name) is not going to work. To concatanate strings together, you use the .. operator like this.

local path = "path"
local file = "file"
newpath = path.."/"..file

newpath now contains "path/file".
Lyqyd #4
Posted 08 December 2012 - 08:33 AM
Also, when you want to build a path name from two strings, you should really use fs.combine, as it is designed to handle all combinations of slashes at the beginning/end of the subject strings.
cheekycharlie101 #5
Posted 09 December 2012 - 12:16 AM
Thanks for all the help guys