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

[Lua][Error]/[Question] Expected string

Started by kelevra.1337, 24 December 2012 - 10:34 AM
kelevra.1337 #1
Posted 24 December 2012 - 11:34 AM
Hey Guys,

I'm having a litte problem that is really limiting me in what i can do in CC:
I've made a test program to test some stuff for an api i want to make but every time i run it, it gives me an error message (line 20: expected string)


local posdata = {}
local data = {}

local id = os.getComputerID()

function createPos()
rednet.open("right")
local x,y,z = gps.locate(2)
rednet.close("right")
posdata[1] = x
posdata[2] = y
posdata[3] = z
posdata[4] = dir
end

function savePos()
createPos()
local file = fs.open(id,"w")		   <------here is line 20
test = textutils.serialize(posdata)
file.writeLine(test)
file.close()
end

If i put it in quotation marks there it just titles the file "id" and not 1 or whatever the computer id is.
Whats really wierd is the fact that i get the same error message even when i copy paste example code in my skript


function save(table,name)
local file = fs.open(name,"w")
file.write(textutils.serialize(table))
file.close()
end

The last time i got this problem i somehow worked around it but now i dont know what i could do to make it work

Thanks in advance if someone can help me/explain the problem, im really desperate and tried many things but nothing worked.
NDFJay #2
Posted 24 December 2012 - 11:49 AM
use


local file = fs.open(tostring(id),"w")

that should fix the error
kelevra.1337 #3
Posted 24 December 2012 - 12:39 PM
Thank you, like seriously. This was a really big problem you just fixed for me :)/>