Jump to content




How to make fs.exists work


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

#1 diamondpumpkin

  • Members
  • 59 posts
  • LocationPlaces, Ukraine

Posted 30 April 2015 - 09: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 by diamondpumpkin, 30 April 2015 - 09:17 PM.


#2 flaghacker

  • Members
  • 655 posts

Posted 30 April 2015 - 09: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 by flaghacker, 30 April 2015 - 09:35 PM.


#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 30 April 2015 - 10:43 PM

@flaghacker - rednet.receive does not return distance, it returns:

number senderID, string message, string protocol

http://computercraft.../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 by KingofGamesYami, 30 April 2015 - 10:44 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users