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

[error] io: Unsupported Format?

Started by Zudo, 29 October 2012 - 04:37 PM
Zudo #1
Posted 29 October 2012 - 05:37 PM
I concatenated a string + a variable + a string and used the IO API to read the contents of a file.
And I got IO: Unsupported format.
Please Help?

remiX #2
Posted 29 October 2012 - 05:45 PM
Show the code
Zudo #3
Posted 30 October 2012 - 08:50 AM
Hang on one sec.
Zudo #4
Posted 30 October 2012 - 09:09 AM
Server Code:

rednet.open("top")
while true do
a, b, c = rednet.receive()
e = "baccounts/" .. b .. "/balance.txt"
print(e)
io.open(e)
d = io.read("*a")
rednet.send(a, d)
end

Client API code

function init()
 os.loadAPI("spd")
end
function login(Ucode)
 rednet.open("right")
 rednet.send(7, Ucode)
 i, rec, d = rednet.receive(5)
 if rec == Ucode then
  spd.setData("login", Ucode)
 end
end
function printBalance()
 rednet.open("right")
 login = spd.getData("login")
 rednet.send(8, login)
 i, rec, d = rednet.receive(5)
 print("Your balance is:" .. rec)
end

Semi Persistant Data code

local data = {}
function getData(key)
return data[key]
end
function setData(key, value)
local oldData = data[key]
data[key] = value
return
end
remiX #5
Posted 30 October 2012 - 09:17 AM

rednet.open("top")

while true do

a, b, c = rednet.receive()

e = "baccounts/" .. b .. "/balance.txt"

print(e)
io.open(e)

d = io.read("*a")

rednet.send(a, d)

end


That is not how you open a file…


rednet.open("top")
while true do
a, b, c = rednet.receive()
  if b then
	e = "baccounts/" .. b .. "/balance.txt"
	print(e)
	file = fs.open(e,"r")
	if file then
	  fileText = file.readAll()
	  print(fileText) -- this will print what is in the 'e' file - if it exists.
	else
	  print("File not found")   -- If file is not found, it will print this.
	end
  file.close()
  end
sleep(0)
end

Try this, it should work - if file 'e' exists.

A better way to use this would be to use e = os.pullEvent("rednet_message") but I'm not sure where exactly to put it and how to use.
Lyqyd #6
Posted 30 October 2012 - 01:39 PM
We should really be recommending use of io.open rather than fs.open.
KaoS #7
Posted 30 October 2012 - 01:39 PM
We should really be recommending use of io.open rather than fs.open.

YESSS. do away with fake wrappers :P/>/>
Lyqyd #8
Posted 30 October 2012 - 02:42 PM
We should really be recommending use of io.open rather than fs.open.

YESSS. do away with fake wrappers :P/>/>

Well, in ComputerCraft's case, io actually wraps fs. However, io has better features and actually is what you would be using when using Lua outside of ComputerCraft, so it's a much better habit to use io than fs for opening files.
KaoS #9
Posted 30 October 2012 - 02:49 PM
wait what :P/>/> now IO is a wrapper….. ok I give up
ChunLing #10
Posted 30 October 2012 - 06:49 PM
Hmmm…it does seem to have nicer features. As for being a wrapper, it has to be because of CC computers not being real and only existing inside of minecraft.
remiX #11
Posted 30 October 2012 - 06:55 PM
I've been using fs instead of io because people say fs is better :? What more does io have?
Cloudy #12
Posted 30 October 2012 - 06:57 PM
It just supports more of the io library. It is also consistent with other things that use Lua. None of them are "better" per say, but for cross compatible code io is your best bet.
Lyqyd #13
Posted 30 October 2012 - 07:00 PM
For instance, handle:lines() for iterating through a file has no equivalent in ComputerCraft's fs library.
remiX #14
Posted 30 October 2012 - 07:49 PM
Ohhh, wow that's awesome :P/>/>