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

How to make fs.exists work

Started by diamondpumpkin, 30 April 2015 - 08:17 PM
diamondpumpkin #1
Posted 30 April 2015 - 10:17 PM
When I try to make a system that checks for money in a computer I try to use fs.exists to check if a file (an account) is there, it doesn't work. It just says false… But when I type print(fs.exists(message) it prints true, because the file is there but the coding doesn't know that. And says false, how do I make it say true?

Coding: http://imgur.com/Icq9qjL
Edited on 30 April 2015 - 08:17 PM
flaghacker #2
Posted 30 April 2015 - 10:33 PM
Please post your code on pastebin in te future.

1) rednet.receive returns id, distance, message. You got them wrong.
2) fs.exists returns a boolean, and you are conparing it to the filename (a string). That will never be true. I think you'll want something like this:

local id, distance, msg = rednet.receive()

if fs.exists (msg) then
  --code here
end

Edit: I assume the random space at line 3 if a font bug and that there's a lot of stuff offscreen in the if's.
Edited on 30 April 2015 - 08:35 PM
KingofGamesYami #3
Posted 30 April 2015 - 11:43 PM
@flaghacker - rednet.receive does not return distance, it returns:

number senderID, string message, string protocol

http://computercraft.info/wiki/Rednet.receive

However, fs.exists( "File" ) will never be equal to "File" because
a - "File" is a string
b - fs.exists returns true or false
Edited on 30 April 2015 - 09:44 PM