Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
TI Basic doesn’t allow real subroutines, but instead uses external programs. Here’s an example that draws 3 different colored lines in a continuous loop using an internal subroutine. Variables are passed to the subroutine using a list. S1(1) contains the return value, S1(2) contains the Y line position, and S1(3) contains the line color. I was wondering if this is an OK way to use internal subroutines or will it eventually cause problems if used in larger programs. I did a search for subroutines but didn’t find anything useful. Also, is there a better way of doing this.

PS. Something should probably be added to the end of the subroutine in case none of the if statements match.



Code:

Goto A

”DRAW LINE SUBROUTINE
Lbl DL
For(Z,1,260)
Pxl-On(ʟS1(2),Z,ʟS1(3))
End
If ʟS1(1)=1:Goto R1
If ʟS1(1)=2:Goto R2
If ʟS1(1)=3:Goto R3
”END SUBROUTINE

Lbl A

While 1
ClrDraw

{1,100,GREEN}→ʟS1
Goto DL
Lbl R1

{2,75,RED}→ʟS1
Goto DL
Lbl R2

{3,50,NAVY}→ʟS1
Goto DL
Lbl R3

End
See TI-Basic Developer's article on this matter. I like the For( loop method, if external subprograms are not an option.
Thanks Nik; I looked at that before, but it didn’t seem to make any sense to me. I went back and reread it and thought I’d just ignore what they were doing with the number and just apply it to my program above setting S1(1) with a specific value. Everything worked OK and that eliminated a lot of extra code.
You should be doing something like this:

Code:
While 1
ClrDraw
For(A,0,2
For(Z,1,260
Pxl-On(100-25A,Z,int(9ln(5-tan(A
End
End
End


Here is the closest one can get to an "Internal TI-BASIC Subroutine":

Code:
PROGRAM:SUB

If pi=Ans(1:Then
For(Z,1,260
Pxl-On(Ans(2),Z,Ans(3
End
Return
End

While 1
ClrDraw

{pi,100,GREEN
prgmSUB

{pi,75,RED
prgmSUB

{pi,50,NAVY
prgmSUB

End
Here the program functions like its own subprogram.

Or, if you want to keep using the horrible and inefficient Label method, you can get super control-hackish and do something like this:

Code:
While 1
ClrDraw

{100,GREEN
For(L,-1,0:If L:Goto DL:End

{75,RED
For(L,-1,0:If L:Goto DL:End

{50,NAVY
For(L,-1,0:If L:Goto DL:End

End

Lbl DL
For(Z,1,260
Pxl-On(Ans(1),Z,Ans(2
End
End
Basically, this method invokes a For( loop so the interpreter starts looking for an End when the interpreter makes the jump to the label (which is really slow btw), it is still looking for the End. When it finally finds it, it will bounce back to the [/mono]For( loop. the [mono]If in the loop causes our routine to not be executed twice. Though you want to be really careful with this method because it can very easily create leaks if used improperly.

In all seriousness though, don't use labels. If you think you need subroutines, rewrite your code :)
LogicalJoe; I was able to change my code similar to your second code listing. That seems to be the easiest one and it cut the code down a lot.

Thanks for the examples.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement