Author Topic: Best TI-BASIC command of all time?  (Read 13338 times)

0 Members and 1 Guest are viewing this topic.

Offline asi14

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 11
  • Rating: +1/-0
    • View Profile
Best TI-BASIC command of all time?
« on: March 11, 2014, 11:25:35 pm »
What is your fav command in TI-BASIC? Comment for any other commands  :w00t: :w00t: :w00t: :w00t: :w00t: :w00t: :w00t:
« Last Edit: March 12, 2014, 12:36:22 pm by Runer112 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #1 on: March 12, 2014, 12:10:59 am »
It's hard to tell considering some are useful in specific places while others are in others. However, it has to be getkey for me, since that's pretty much essential for most decent games.

Also let's avoid titles written in all-caps.

Offline TheCoder1998

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 434
  • Rating: +20/-2
  • my art is written in code, not in graphite
    • View Profile
    • My website :D
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #2 on: March 12, 2014, 02:14:04 am »
why is prompt included in the poll?
input is (imo) much better
my ticalc acc:

http://www.ticalc.org/archives/files/authors/113/11365.html

Spoiler For The Best Song Ever:


follow me on tumblr :)
www.rickdepizza.tumblr.com

check out my anilist :D
http://anilist.co/animelist/29701/Rickdepizza

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #3 on: March 12, 2014, 02:25:32 am »
It can be smaller in some cases, though, such as if you want the "H=?" prefix or whatever displays before the ?  without having to enter a string before the var.

Offline Lunar Fire

  • LV3 Member (Next: 100)
  • ***
  • Posts: 66
  • Rating: +7/-1
  • I'll be watching you from the shadows
    • View Profile
    • My Tumblr
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #4 on: March 12, 2014, 02:35:16 am »
I think a "favorite" Basic instruction is a bit of a stupid question. Those commands all serve a purpose and some are more appropriate in a specific context than another. So in a way, all of them are my favorite. Except goto. Go to hell goto. Bring your little brother Lbl along with you please.
Your drill is the drill that will pierce the heavens!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #5 on: March 12, 2014, 02:44:33 am »
On the other hand, in one very rare case, Goto is actually faster than While/For-End O.O

Offline Lunar Fire

  • LV3 Member (Next: 100)
  • ***
  • Posts: 66
  • Rating: +7/-1
  • I'll be watching you from the shadows
    • View Profile
    • My Tumblr
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #6 on: March 12, 2014, 02:51:27 am »
Since Goto reads from top to bottom, wouldn't this case be if the Lbl instruction is the very first?

Also, Goto seem to break flow of code and mess up the call stack, so it is not reccomended to use it. For some it is despicable to use it. I tend to keep my code free of gotos, but I know a lot of programmers use them.
Your drill is the drill that will pierce the heavens!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #7 on: March 12, 2014, 02:53:46 am »
Indeed, and even then it would not be applicable in the case where you need to do For(Z,0,1000:End, for example.

But yeah I haven't used a Goto in my calc games since June 2004.

Offline TheCoder1998

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 434
  • Rating: +20/-2
  • my art is written in code, not in graphite
    • View Profile
    • My website :D
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #8 on: March 12, 2014, 10:27:29 am »
what could be a substitute for goto then?
i find it very useful
my ticalc acc:

http://www.ticalc.org/archives/files/authors/113/11365.html

Spoiler For The Best Song Ever:


follow me on tumblr :)
www.rickdepizza.tumblr.com

check out my anilist :D
http://anilist.co/animelist/29701/Rickdepizza

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #9 on: March 12, 2014, 11:00:57 am »
Mine would be sum(. I use it all too often in my games. Examples of my code snippets with sum(:

Cookie Clicker:
Code: [Select]
If checkTmr(T
Then
C+checkTmr(T)sum(L1L3->C
startTmr->T
End

Shutdown:
Code: [Select]
Repeat K=45 and sum(L₁
My Snow Demo:
Code: [Select]
If not(sum(L1(D)+1=L1
Then
Output(int(L1(D)),100fPart(L1(D)),"
1+L1(D->L1(D
Ans+.01randInt(~1,1
If fPart(Ans) and fPart(Ans)<.17 and not(sum(Ans=L1
Ans->L1(D
Output(int(L1(D)),100fPart(L1(D)),"*
Else
If D=S
D+1->S
End


Sum is useful. :)
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #10 on: March 12, 2014, 11:10:47 am »

Personally, I stand by the Case Against Goto: [size=78%]http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF[/size]

...but...Quoth Xeda:



Personally, for TI-BASIC and many other languages, I find Goto is excellent. Having written several programming languages and evaluating the code for the TI-BASIC parser, Goto has one main disadvantage and one main advantage, if used properly, and one massive advantage if used improperly like a pro, and one disadvantage if used improperly like a new programmer:


Speed wise, in TI-BASIC, Goto will be slower than While, Repeat, and For(. This is because the BASIC parser stores data in its operator stack telling precisely where to jump upon looping. If I remember correctly, it stores the variable name, and the offset into the variable for where the loop starts. This is still pretty slow, and there are more complicated things that happen, too, but it basically lets the parser use a look-up table (LUT) for loops. Gotos on the other hand must search for the label in the program. If the label is near the end of a program that is >10000 bytes, for example, it will be noticeably slower jumping there than to the beginning. However, this consumes no memory.


There is a misconception that Gotos and Lbls can cause memory errors. This is not true. It is like saying guns kill people. It's not true. They may help, but ultimately, it is somebody else abusing them that causes it. In reality, While, Repeat, and For( cause the memory leaks. Remember how I said that they push data onto an operator stack? That data only get removed on completion of the loop. If you use Goto to improperly exit the loops, then that data doesn't get taken offnot necessarily true; see below and reentering that loop causes it to push again, and again, and again, eventually making you run out of RAM.


Somebody who is versed enough in the TI-BASIC language knows that this can actually be useful for creating a structure not included in TI-BASIC, but should have been -- subroutines. The parser removes an item from the operator stack once it reaches an End. So what you could do is a complicated rebranching of a While loop using Goto:
Code: [Select]


                While A>0 If remainder(A,2 Goto 1 /  | /   | /----------    | Lbl 1              | Disp 1          Disp 0 int(.5A→A       .5A→A End             End
*btw, formatting got off here
Looking at it this way, you see that it won't actually cause a memory leak because the parser doesn't care where or when it comes across an End. As long as it does, reach one, it will jump back to the start of the loop. However, in actual BASIC code, because it is linear, it might look something like the following:
Code: [Select]
While A>0 If remainder(A,2 Goto 1 Disp 0 .5A→A End Lbl 2 <<do stuff now that the loop is over>> Lbl 1 Disp 1 int(.5A→A End Goto 2   ;in case A becomes 0 because of this branch, it doesn't loop back, so we have to manually jump there.
Looking at it this way, you see that it won't actually cause a memory leak because the parser doesn't care where or when it comes across an End. As long as it does, reach one, it will jump back to the start of the loop. However, in actual BASIC code, because it is linear, it might look something like the following:


While this is by no means an efficient application of this idea, here is a program where I used that trick quite a bit to make a subroutine for sprite drawing, saving, and items menu so that I could call the routine at any point in my program without using sub programs or rewriting the routine.


Needless to say, I think Lbl and Goto are very useful. They shouldn't be used in places where While, Repeat, and For( are more efficient, but in TI-BASIC, where efficiency is key, Goto has its place.
[size=78%]






...and, in an effort to be on topic, my favorite command is seq(), with the ability to create lists of all kind, to be manipulated in many ways. It's very versatile.[/size]
« Last Edit: March 12, 2014, 11:15:08 am by dinosteven »

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #11 on: March 12, 2014, 11:27:34 am »
Dino, I too think that Goto does have its place (heck, I preferred it over a While loop in my Shutdown game, and then there was this big argument...you had to be there, I guess). It still is kinda inefficient, though; you could use loops instead on most occasions. :/

And I also think that a useful command is Ans. Ans helps for optimizations in both size and speed...it's all-around good.

Finally, I want to expand on Dino's idea of "subroutines". I actually know of code for that (use any label other than S for the subroutine, and any variable you want in the loop instead of S, just make sure the subroutine doesn't modify it!):
Code: [Select]
:ClrHome
:Disp "MAIN PROGRAM
:For(S,-1,0
:If S
:Goto S
:End
:Disp "MAIN AGAIN
:For(S,-1,0
:If S
:Goto S
:End
:Disp "BACK IN MAIN
:Return
:Lbl S
:Disp "SUBROUTINE
:End
This should display MAIN PROGRAM,SUBROUTINE,MAIN AGAIN,SUBROUTINE,BACK IN MAIN on the homescreen in 5 lines.

I have never come across a situation where I'd use this in my programs, but I would if I ever did. I recommend that to other BASIC programmers...it helps. ;)
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: BEST TI-BASIC COMMAND OF ALL TIME???
« Reply #12 on: March 12, 2014, 11:58:06 am »
Does Ans qualify as a "command", per se? Yeah, it's extremely useful for optimizations, but I'm pretty sure it's categorized as a variable.
Again, I'm anti-Goto, and that was just a copy paste from Xeda on TIBasicDev forums a while back.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Best TI-BASIC command of all time?
« Reply #13 on: March 12, 2014, 04:31:13 pm »
Does Ans qualify as a "command", per se? Yeah, it's extremely useful for optimizations, but I'm pretty sure it's categorized as a variable.
Again, I'm anti-Goto, and that was just a copy paste from Xeda on TIBasicDev forums a while back.
It should be, but it isn't. :-\
And I was wondering where I saw that before...
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline tifreak

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2708
  • Rating: +82/-3
  • My Kung Fu IS strong...
    • View Profile
    • TI-Freakware
Re: Best TI-BASIC command of all time?
« Reply #14 on: March 12, 2014, 05:18:20 pm »
I'd have to say While is by far my favorite command, and I use it for everything. I figured out how to use it to replace Goto/Lbl, and allow me to incorporate subroutines into the main code so I have less sub programs in the menu.
Projects: AOD Series: 75% | FFME: 80% | Pokemon: 18% | RPGSK: 60% | Star Trek: 70% | Star Trek 83+: 40% | TI-City: 5%