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

For some reason, this isn't setting the variable properly?

Started by LezChap, 30 May 2016 - 06:34 AM
LezChap #1
Posted 30 May 2016 - 08:34 AM
Okay, I'm having a problem in my code…and it's probably something simple, but I've tried tweaking this many times, troubleshooting and debugging everything I can think of, and I think it just needs a fresh set of eyes. The following are the pastebins for my code (and the Touchpoint API, made by Lyqyd plus a small section added by me for making boxes that aren't buttons): Main Code and API.

The problem? When I call nextPage(str) (line 60) or prevPage(str) (line 70), the program behaves as expected, and I flip to the next or previous page. tp=pages[currPage] works. In searchCows(str) (line 80), the tp=pages[currPage] does not seem to set the tp variable, and the new page fails to display. I know the search page/keyboard needs some graphical/alignment tweaking, but it DOES display if I set line 282 to "tp = pages["search"]" before my first tp:draw(). I'm not understanding why it's setting the variable and displaying the correct page when the variable is a number, but not when that variable is a string. I even tried changing line 84 to "tp = pages["search"] like what worked on line 282 while testing, and that didn't seem to fix the problem. The reason I think it's not setting the variable properly because during my troubleshooting/debugging, in the searchCows function I set a test variable and verified that it was the value I set while within the function, but then when I printed it in my while loop (a few lines of code later, execution-wise), that variable was nil.

Please point out the probably trivial thing I'm missing and pulling my hair out trying to find.
Bomb Bloke #2
Posted 30 May 2016 - 11:09 AM
You intend to have line 41 create a button that calls the function that "searchCows" will point to, but since you don't actually assign that pointer to "searchCows" until line 80, the add function is passed nil instead. The resulting button won't run any function.
LezChap #3
Posted 30 May 2016 - 02:53 PM
And it was something completely stupid. Thanks for pointing it out (sincerely, I really needed another set of eyes on it). In making this I've reordered and re-created how I've processed through things so many times I forgot when I was calling things vs when I was declaring/defining them…Moved them around into a "proper" order and they're now working as intended. I'll leave the old pastebin up (from the OP, for as long as I can at least) so people can see what you're talking about/pointing out, and the new working (and working copy of the pastebin) is http://pastebin.com/pwFqt7aA if anyone wants to see and/or follow the changes as I finish implementing the search feature.