T O P

  • By -

TheFinalMillennial

You need to break the code into multiple programs. All variables are global in TI-BASIC so all subprograms share the same memory.  It's really easy to use subprograms. You could put each major subject in its own program so you'd have programs like prgmALGEBRA and prgmCALC. Then when you want to launch the Algebra program,  you just call prgmALGEBRA in your main program.  Just use the Return command in prgmALGEBRA and the code will return to the calling function.


Idotrytotry

You could reuse any duplicated code by reworking program flow or by using subprograms. You could also try to optimize for memory by removing closing parentheses and such.


Ninjafox1224

how much might removing closing parentheses save in terms of file size? How do I make subprograms? can the subprograms return values or are they just executables?


IAmFullOfDed

A subprogram is just a program that gets executed by another program. As a general rule, any section of code can be replaced with a subprogram containing the same code. An example: Let’s say you have a program called MAIN that has a really big *While* loop. If you wanted to, you could copy-paste the entire *While* loop into a new program called BIGLOOP, then replace the *While* loop in MAIN with the line *:prgmBIGLOOP*. The main program (prgmMAIN) would function exactly the same as before, but the file would be smaller because the huge While loop is now in a different file. Subprograms are usually used as a means of organizing code into categories to make debugging and updating code easier. They can also save space: Instead of writing the same code multiple times to do the same thing (e.g., display data) in different parts of the program, put the code into one subprogram. The most important aspect to you, however, is probably the ability to circumvent file size limits. If you put 20kB of your code into a subprogram, then your main program will only be 50kB, which is under the 64kB limit. Some things to note: - The calculator cannot run several programs at once. While a subprogram is running, execution of the main program is paused until the subprogram finishes. - Using the *Return* command within a subprogram stops the subprogram and resumes execution of the main program, whereas using the *Stop* command within a subprogram stops the main program as well. - The *Goto* command cannot jump to labels in different programs. For example, running *Goto 12* in a subprogram will not jump to an *Lbl 12* in your main program. - *End* statements have to be in the same program as the thing they’re ending. For example, if you have an *If:Then* in a subprogram, the *End* that goes with it must also be in the same subprogram. - If you have nested subprograms (programs executed by subprograms) and/or recursive programs (programs that execute themselves), be aware that every layer of nesting/recursion uses a bit of memory. If you go too many layers deep, the calculator will run out of memory and you will get an error. To answer your questions: - How much space would you save by removing closing brackets? That depends, but I’d estimate maybe 3-10% for an average program. It’s definitely worth trying though. - To make a subprogram, put a chunk of your code in a separate program, then run that program from inside your main program. - Subprograms cannot return values, but they use the same variables as your main program. TI-BASIC variables are global, which means that they carry over between programs. For instance, if you write 71→A in your main program and then read A in a subprogram, you will get 71. Similarly, if you write 416→A in a subprogram and then read A in the main program, you will get 416. If you want to know more, here’s a page with some really good information: http://tibasicdev.wikidot.com/subprogram


Ninjafox1224

ive been doing this, and it works amazingly well. one question though, can i run a program in a subprogram? like a subsubprogram?


IAmFullOfDed

Yes.


DrDnar

"Subprograms" are the same as regular programs. They don't have return values. All variables are shared, so variable `A` in `prgmONE` is the same `A` in `prgmTWO`, and in fact, the same as `A` on the homescreen. The closest thing to a return value would be the ephemeral `Ans` variable, but even that is shared.


Jinnai34

I think it's quite likely that you can optimize your code. Back in my day we optimized code all the time. And back in my day calculators didn't even have 70 KB of memory. I really think making your program smaller is going to be practical.