here is my problem in a nutshell, I have started programming with ti basic about 3 months ago and have come to create some pretty enjoyable games and useful tools along the way. my calculator has gone from a dumb lump of plastic to a genuine source of entertainment. in fact i prize my creations very much and would like to ensure they are safe. So what better way to do that then to password protect my calculator from teachers and pranksters looking to erase my stuff? thats just what i did. I downloaded the startup program and set to work making my own passcode program (i dont trust ones made by other people on the interwebs). the first time i finished and ran into a problem, i used input to get a user response. this turned out to be a flaw because processing is paused while it waits for input. that means any user could simply type 2nd, quit and exit anytime they wanted…not very effective. so the second time i made it, i took a different approach. I designed it so that it repeated a get key command until something was pressed and then if the key pressed was not the first number of the password it would restart the program (this is in case someone presses second, it will restart before they can quit it), if it was right then it would do the same thing agian but nested inside an "else" of the last if statement until the last key was pressed. then it would end and allow use of the calulator
PROGRAM:PASS :ClrHome \\setup :0->K \\setup :Disp “my calculator”,”please enter password”,”---------------“ \\menu stuffs :Repeat not(K=0 :getkey->K \\wait until key pressed :end :If not(K=93 :then \\if not key "2" then restart :prgmPASS :else \\otherwise if key "2" was presssed then :Repeat not(K=0 :getkey->K \\wait for second keypress :end :If not(K=72 :then :prgmPASS \\if its not the second number in the passcode, restart :else \\but if it is then... :Repeat not(K=0 :getkey->K \\wait for the third keypress :end :if not(K=94 :then \\if its not the third number in the sequence the restart :prgmPASS :else \\otherwise look for the last number by... :Repeat not(K=0 :getkey->K \\waiting for the fourth key press :end :if not(K=102 :then \\and if its not the final digit then restart :prgmPASS :else :pause “correct!” \\otherwise let the user through and quit the program :clrHome :stop :end :end \\bunch of ends to wrap things up :end :end
In concept and during initial testing it works beautifully, it's everything a programmer could dream of, it prevents users quitting it and runs the code in a secure fashion. but there is one problem. memory leaks. I read on the command page tibasicdev.wikidot.com/if that if you have many nested if statements (like I do) then ti basic uses up 35 bytes every time a new statement is added to keep track of that statement. This is no problem because you get that memory back once it reaches the "end" statement…EXCEPT if you use a goto command. if you use a goto command it jumps out before reaching the end statement and thus that nugget of memory is lost until the program finishes. apparently the same thing applies when i said "prgmPASS" to restart it. that means one can easily press any random button about 25 times before the calculator return "ERR:MEMORY" and its lamely out of memory. at that point one can just press clear and then all the security is bypassed with intruders completely free to erase whatever they want.
I've tried brainstorming many other arrangement but none seem to be able to run this sequence of if's without rampant memory leaks. I'm guessing that the correct setup would go like this:
:\\imagine a get key repeat loop after every if :if K=93 :then :if K=72 :then :If K=94 :then :if K=102:then :stop \\correct answer reached end program here :end :end :end :end :prgmPASS \\the wrong key was pressed somewhere along there so place the restart at the end because \\it will go here all not all if statements are satisfied
I haven't tested this yet but im sure there is something wrong with it. i need someone who can visualize a setup that will work for sure because my brain is fried from all this thinking. Any help would be greatly appreciated!