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

can't use a variable containing string

Started by Digamma, 25 August 2016 - 04:30 PM
Digamma #1
Posted 25 August 2016 - 06:30 PM
(Sorry for my bad English, I'll do my best)
I entered this in interactive lua prompt :

local target = "test"
local file = fs.open(target, "r")

And an occur happen :

Expected string, string

I saw tutorials about string type, how to read a file, about fs . . .
I don't know what to do, please help . . .
Lyqyd #2
Posted 25 August 2016 - 07:35 PM
That code would work fine in a program, but the Lua prompt localizes variables to just that line. They'll be nil when you enter the next line. Remove the local keyword while you're testing code in the Lua prompt.
Digamma #3
Posted 25 August 2016 - 11:05 PM
thanks you so much :)/>