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

[solved] window:179: bad argument: string expected, got nil

Started by Nhorr, 04 November 2015 - 05:14 PM
Nhorr #1
Posted 04 November 2015 - 06:14 PM
Solved. Thanks again, Bomb Bloke!

Yet another classic "string expected, got nil" error, but I just can't find the fault.
Any help would be very greatly appreciated.

Code in question: http://pastebin.com/JUhsDLDd

Many thanks in advance!
Edited on 11 February 2016 - 02:04 PM
Bomb Bloke #2
Posted 04 November 2015 - 10:04 PM
There are a couple of ways to track this sort of fault (errors in some other code, triggered by your code).

One is to set break points in your code. Dot print statements throughout it with unique/random messages, along with os.pullEvent("char")s so that they stay on the screen until you hit a key to bypass them. This allows you to narrow down which of your lines is causing the problem.

Another, which applies to the window API specifically, is to prevent said API's use in the first place. Advanced computers run all code through windows by default (to make multishell work), but sticking a "term.redirect(term.native())" up the top of your script bypasses the one your tab's using - and changes the error to point to line 104 in your code, with an "expected number":

term.setBackgroundColor(deskColors[backColor])

deskColors[backColor] is undefined, as you never defined a stand-alone backColor variable. You meant to type either deskColors.backColor or deskColors["backColor"], either of which would refer to the backColor key in the deskColors table.
Nhorr #3
Posted 05 November 2015 - 07:53 PM
There are a couple of ways to track this sort of fault (errors in some other code, triggered by your code).

One is to set break points in your code. Dot print statements throughout it with unique/random messages, along with os.pullEvent("char")s so that they stay on the screen until you hit a key to bypass them. This allows you to narrow down which of your lines is causing the problem.

Another, which applies to the window API specifically, is to prevent said API's use in the first place. Advanced computers run all code through windows by default (to make multishell work), but sticking a "term.redirect(term.native())" up the top of your script bypasses the one your tab's using - and changes the error to point to line 104 in your code, with an "expected number":

term.setBackgroundColor(deskColors[backColor])

deskColors[backColor] is undefined, as you never defined a stand-alone backColor variable. You meant to type either deskColors.backColor or deskColors["backColor"], either of which would refer to the backColor key in the deskColors table.

Thanks! I'll get on it soon.

EDIT: Wow. That was a simple fix. Added quotation marks to all mistakes like the backColor one and now it's working fine and dandy (well, it's got other issues, but at least now I can actually focus on troubleshooting now that the code actually works again). Thanks again, and I'll make sure to reference this if I ever have a similar issue!
Edited on 06 November 2015 - 01:26 AM