Jump to content




Attempt to call string.


  • You cannot reply to this topic
4 replies to this topic

#1 cheekycharlie101

  • Members
  • 231 posts

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

#2 Doyle3694

  • Members
  • 815 posts

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 /

#3 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 08 December 2012 - 07:41 AM

View PostDoyle3694, on 08 December 2012 - 07:36 AM, said:

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".

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#5 cheekycharlie101

  • Members
  • 231 posts

Posted 09 December 2012 - 12:16 AM

Thanks for all the help guys





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users