I'm currently making a turtle miner program from scratch. Although there is already a program in the turtle itself that does what I want it to do, I wanted to challenge myself. This program, beyond the program in the turtle itself, will contain a GUI program inside a computer (which will send various commands via rednet), where you will be able to set different variables, dynamically stop the mining process, etc. I'm currently working on the computer part, but I quickly found a problem on the buttons.
You see, I want my GUI to have cycling buttons, aka, a selector with two buttons, one of which will increment the value of the selector and another button which will decrement the value. This type of button will be used to set both colors (background color, text color...) and numbers (specifically for the mining area).
The problem that I'm having is that, whenever I run the code, the computer registers the buttons, but crashes when drawing them. It says something along the lines of 'window 57: Expected number' and shuts itself off. I've tried to work around the function that draws the buttons, but nothing seems to work, since the program keeps crashing all the time. Here's the code: http://pastebin.com/3BXYnbiC
Rotating Buttons
Started by Writer, Sep 19 2015 11:52 AM
4 replies to this topic
#1
Posted 19 September 2015 - 11:52 AM
#2
Posted 19 September 2015 - 12:10 PM
addButton(1, 5, 9, 3, 'color', defaultColors[9], 2)...
function addButton(id, decrement, increment, y, type, color, value)
registeredButtons[id] = {}
registeredButtons[id]['minX'] = decrement
registeredButtons[id]['maxX'] = increment
registeredButtons[id]['y'] = y
registeredButtons[id]['type'] = type
registeredButtons[id]['btn_color'] = color
registeredButtons[id]['value'] = value
end
...local bColor = defaultColors[data.btn_color]
You end up with nil, since defaultColors[ 256 ] doesn't exist. From the first snippet, change it to simply '9', not defaultColors[ 9 ] or change the last snippet to just data.btn_color.
If you didn't already know, that particular error means a term function that expected a number didn't get one - culprits are commonly term.setCursorPos and term.setBackgroundColor.
#3
Posted 19 September 2015 - 01:30 PM
Dang, I had done the same mistake on another parameter on the same function. Looks like I can't have multiple ideas while programming. Nevertheless, I changed the program but it keeps giving me the same error.
#4
Posted 19 September 2015 - 01:44 PM
Intersperse print statements throughout your script (or writes to a log file, whatever's easier for you) so you can pinpoint the line within your code that's leading to the error within the window API - as Yami notes, it'll be one of the ones where you call a term function. Once you've figured out the culprit, have the script print out the values you're passing to the problematic term function before it goes ahead and does so. You'll then know which variable has the incorrect value, and can start work of figuring out how it got that way.
#5
Posted 19 September 2015 - 02:00 PM
Bomb Bloke, on 19 September 2015 - 01:44 PM, said:
Intersperse print statements throughout your script (or writes to a log file, whatever's easier for you) so you can pinpoint the line within your code that's leading to the error within the window API - as Yami notes, it'll be one of the ones where you call a term function. Once you've figured out the culprit, have the script print out the values you're passing to the problematic term function before it goes ahead and does so. You'll then know which variable has the incorrect value, and can start work of figuring out how it got that way.
I actually made that on the original code. Ended up figuring out what the problem was. Apparently, the sColor variable should be declared either as a pointer (I believe this is the term for 'local sColor') outside the if/else statement or as a global variable. I didn't know that local variables inside if/else statements could only be used inside these statements.
KingofGamesYami, on 19 September 2015 - 12:10 PM, said:
addButton(1, 5, 9, 3, 'color', defaultColors[9], 2)...
function addButton(id, decrement, increment, y, type, color, value)
registeredButtons[id] = {}
registeredButtons[id]['minX'] = decrement
registeredButtons[id]['maxX'] = increment
registeredButtons[id]['y'] = y
registeredButtons[id]['type'] = type
registeredButtons[id]['btn_color'] = color
registeredButtons[id]['value'] = value
end
...local bColor = defaultColors[data.btn_color]
You end up with nil, since defaultColors[ 256 ] doesn't exist. From the first snippet, change it to simply '9', not defaultColors[ 9 ] or change the last snippet to just data.btn_color.
If you didn't already know, that particular error means a term function that expected a number didn't get one - culprits are commonly term.setCursorPos and term.setBackgroundColor.
Yap. That was the other problem. Thank you very much to both of you for your help!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











