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

window:88: Expected Number

Started by Towtow10, 29 January 2016 - 11:53 PM
Towtow10 #1
Posted 30 January 2016 - 12:53 AM
I am trying to run some code that read text from a file and places it in a variable, however I get the error

window:88: Expected Number

Here is my code:

local handle = fs.open(".settings/theme", "r")
theme = handle.readLine()
handle.close()

How can this be fixed?
Lyqyd #2
Posted 30 January 2016 - 12:57 AM
How about the rest of your code?
Towtow10 #3
Posted 30 January 2016 - 12:59 AM
How about the rest of your code?
its too big to put here
Anavrins #4
Posted 30 January 2016 - 01:14 AM
How about the rest of your code?
its too big to put here
Well, isn't that unfortunate.
You could put it on pastebin or something, but without your code, we can't really help you that much.
Though, I can tell you it's something about term.setTextColor receiving a non-number argument somewhere in your code, couldn't tell you where.
There's also another issue, if you're going to use .settings as a folder, you will break the CC1.77 settings api some way or the other.
Edited on 30 January 2016 - 12:18 AM
Towtow10 #5
Posted 30 January 2016 - 01:22 AM
How about the rest of your code?
its too big to put here
Well, isn't that unfortunate.
You could put it on pastebin or something, but without your code, we can't really help you that much.
Though, I can tell you it's something about term.setTextColor receiving a non-number argument somewhere in your code, couldn't tell you where.
There's also another issue, if you're going to use .settings as a folder, you will break the CC1.77 settings api some way or the other.
term.setTextColor would be recieving something like this colors.red, that should work
its on line 3297 of http://pastebin.com/cbjqe4pE
and defaultTheme is the text in the theme file.
Edited on 30 January 2016 - 12:34 AM
Dog #6
Posted 30 January 2016 - 01:30 AM
term.setTextColor would be recieving something like this colors.red, that should work
While that *should* work, that isn't what's happening in your code based on the error. Please post your code to pastebin and post the link here. Without seeing your code all we can do is guess.
Towtow10 #7
Posted 30 January 2016 - 01:38 AM
term.setTextColor would be recieving something like this colors.red, that should work
While that *should* work, that isn't what's happening in your code based on the error. Please post your code to pastebin and post the link here. Without seeing your code all we can do is guess.
i did
Lyqyd #8
Posted 30 January 2016 - 01:47 AM
You're setting the theme variable to a string in some places and a table in others. You should probably add some debug prints to determine exactly where the error is being thrown, though.
Towtow10 #9
Posted 30 January 2016 - 01:56 AM
You're setting the theme variable to a string in some places and a table in others. You should probably add some debug prints to determine exactly where the error is being thrown, though.
i dont quite understand what you mean by string in some places and a table in others.
KingofGamesYami #10
Posted 30 January 2016 - 02:30 AM
Line 74 (table)

local theme = {}
Line 531 (string)

    theme = read()
Line 537 (table)

    theme = grayscaleTheme
Line 3298 (string)

        theme = handle.readLine()
Line 3302 (table)

        theme = grayscaleTheme
Dragon53535 #11
Posted 30 January 2016 - 04:09 AM
He's not setting it, he's using GravityScore's and 1lann's code. More than likely, and I hope this is the case, the file he's reading is full of a serialized table, in which he could easily just use this line:

theme = textutils.unserialize(handle.readAll())
Edited on 30 January 2016 - 03:11 AM
Towtow10 #12
Posted 30 January 2016 - 06:27 AM
He's not setting it, he's using GravityScore's and 1lann's code. More than likely, and I hope this is the case, the file he's reading is full of a serialized table, in which he could easily just use this line:

theme = textutils.unserialize(handle.readAll())
stored in the file is

defaultTheme
which refers to line 76.
when I put defaultTheme instead of

handle.readLine()
it works, so why dosent handle.readLine()?
Lyqyd #13
Posted 30 January 2016 - 07:03 AM
A string in a file is just a string, it doesn't "refer to" anything else.
Towtow10 #14
Posted 30 January 2016 - 08:12 AM
A string in a file is just a string, it doesn't "refer to" anything else.
ok, thanks