1114 posts
Location
UK
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?
2088 posts
Location
South Africa
Posted 29 October 2012 - 05:45 PM
Show the code
1114 posts
Location
UK
Posted 30 October 2012 - 08:50 AM
Hang on one sec.
1114 posts
Location
UK
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
2088 posts
Location
South Africa
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.
8543 posts
Posted 30 October 2012 - 01:39 PM
We should really be recommending use of io.open rather than fs.open.
1548 posts
Location
That dark shadow under your bed...
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/>/>
8543 posts
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.
1548 posts
Location
That dark shadow under your bed...
Posted 30 October 2012 - 02:49 PM
wait what :P/>/> now IO is a wrapper….. ok I give up
2005 posts
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.
2088 posts
Location
South Africa
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?
2447 posts
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.
8543 posts
Posted 30 October 2012 - 07:00 PM
For instance, handle:lines() for iterating through a file has no equivalent in ComputerCraft's fs library.
2088 posts
Location
South Africa
Posted 30 October 2012 - 07:49 PM
Ohhh, wow that's awesome :P/>/>