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

Need help with window error

Started by s0r00t, 16 April 2014 - 08:41 PM
s0r00t #1
Posted 16 April 2014 - 10:41 PM
Hello,
I am encountering an error with window api that crashes the pocket computer. This is the error :

window:57:Expected number
And here is the full code of the program (yes, it is the Improved ToDo list) :
http://pastebin.com/FpMjPiAc
I just know that the error comes from here :

if fs.exists("/.todocfg") then
	opfile = fs.open("/.todocfg", "r")
	local color1 = tonumber(opfile.readLine())
	local color2 = tonumber(opfile.readLine())
	opfile.close()
else
	local color1 = colors.lime
	local color2 = colors.white
end
If I add :

	local color1 = colors.lime
	local color2 = colors.white
after the condition, it works.

Where is the problem?

Thanks!
MKlegoman357 #2
Posted 16 April 2014 - 10:47 PM
It's because color1 and color2 are being localized to that if statement. Just create them at the start of your program and then set them in your if statement:

Start of the program:

local color1 = colors.lime
local color2 = colors.white

If statement:

if fs.exists("/.todocfg") then
  local opfile = fs.open("/.todocfg", "r") --// Localizing this wouldn't hurt

  color1 = tonumber(opfile.readLine())
  color2 = tonumber(opfile.readLine())

  opfile.close()
end
s0r00t #3
Posted 16 April 2014 - 10:51 PM
Wow, very fast answer !
I didn't thought about that solution, got angry after seeing this error a dozen times :lol:/>
Thanks a lot !