http://calcg.org/newlogo2.png Not Logged in.
Login | Register

General Discussion Board \ Game and Program Discussion \ Good Advice for a TI-83+ BASIC programmer!

Click here to log in (you must be logged in to post comments).

AuthorComment
joshparis18
Probe
Posted: 27 Sep 2008
11:25 GMT
Total Posts: 14
Just a quick word of advice to any TI-83+ BASIC programmer. Something that took me a little while to discover is the use of the "Goto" and "lbl" commands. At first I thought they were awesome but that's definately NOT the case! The "Goto" and "lbl" commands cause the compiler to have to skip around your code to find the Lbl it's looking for and results in slowing down your program drastically until it runs so slow that you get an error message.

The best way around this is to NOT use the Goto and lbl commands, but rather do "While" loops to complete your task. It might be harder to program that way but it will DRASTICALLY increase the programs speed in the long run. It also will never cause your program to slow down!
tifreak8x
Administrator
avatar
Posted: 27 Sep 2008
17:36 GMT
Total Posts: 419
This is quite the well known fact among most of us programmers... The real reasoning behind the problems you faced:

Everytime the processor sees a Goto, it starts at the begining of the program and scans down, until it finds that Lbl. Doing this out of a loop or If:Then:End line will cause memory leaks, because the calculator has a spot in memory that it keeps track of how many End commands it should run across. If it never gets to them, then of course it will rack up alot of information before running out of memory.

If you want some advanced examples of not using Goto/Lbl, look through http://calcg.org/cgi-bin/files.cgi?id=1172

---
Bringing you Pokemon, for your calculator.
joshparis18
Probe
Posted: 27 Sep 2008
17:49 GMT
Total Posts: 14
Yeah, I already know about it. I just wanted to inform some beginning programmers because I used to make that mistake when I first started programming on the TI calculators. Some people don't realize why their programs run slowly and I was just hoping to clarify it for them.

Thanks for the added info though.
Vectris
Ultralisk
avatar
Posted: 27 Sep 2008
18:58 GMT
Total Posts: 375
I use Repeat over While, what's the big difference? And is one better/smaller/quicker than the other?
joshparis18
Probe
Posted: 28 Sep 2008
06:38 GMT
Total Posts: 14
Well depending on what you are using it for, While loops can be much more helpful. While loops aren't really the same as Repeats anyway are they? I don't normally use the Repeat function. The While loop is mainly used for saying "Do this section of code while this certain statement is true" and Repeats say "No matter what, do this section of code X number of times". So if you're looking to have a section of code that ONLY executes when a certain thing is true (for example, if the user has 0% health THEN display "You're Dead") then it would be more efficient to use a while loop, otherwise the "Return" section of code will always be executed which means it would ALWAYS show that your character is dead even though his health might be at 100%!
Zachary940
Wraith
avatar
Posted: 28 Sep 2008
14:49 GMT
Total Posts: 714
One says yes while the other says no. That is the only diffrence

---
It is much easier to suggest solutions when you know nothing about the problem.
tifreak8x
Administrator
avatar
Posted: 28 Sep 2008
20:02 GMT
Total Posts: 419
Yeah.. While will not run unless the the statement is true, while Repeat will run at least once, until the statement is false. I wrote up a tutorial on alot of this stuff here: Lesson 6 of the tutorial

:)

---
Bringing you Pokemon, for your calculator.
darksideprogramming
Guardian
avatar
Posted: 29 Sep 2008
08:14 GMT
Total Posts: 1005
That reminds me, one of these days I'll get back to working on my tutorials.

In the mean time, I recommend using Repeat whenever possible.
tifreak8x
Administrator
avatar
Posted: 29 Sep 2008
13:50 GMT
Total Posts: 419
NO! Not always <.<

Again, I can use While to move through a program like you would use Lbl/Goto to do the same, and it is far faster. :) While > Repeat

---
Bringing you Pokemon, for your calculator.
darksideprogramming
Guardian
avatar
Posted: 30 Sep 2008
05:29 GMT
Total Posts: 1005
Hey, I didn't say always. :P
joshparis18
Probe
Posted: 30 Sep 2008
16:47 GMT
Total Posts: 14
I agree with TIfreak. I've programmed about 5 full games that I uploaded on the site. One, "Lingo" I was unaware of the Lbl and Goto slowdown errors and the you'll notice the program runs slowly after a while of playing. However in my "Lucky Penny" game (which is far better programmed and much more effecient in code) runs way better when I used While loops to simulate Lbl, Goto commands. While I'm sure Repeat can be used efficiently too, I prefer While loops. They just seem more professional to me.
darksideprogramming
Guardian
avatar
Posted: 1 Oct 2008
06:16 GMT
Total Posts: 1005
Meh, to each his own. I prefer using Repeat since most of the time it saves a byte or two. For example:

Repeat K
getKey->K
End

is better than:

While not(K
getKey->K
End
tifreak8x
Administrator
avatar
Posted: 1 Oct 2008
07:40 GMT
Total Posts: 419
Yes, however:

1->W
While W=1
getkey->K
If stuff:manipulate W
End

Is so much nicer looking. :P And it has the added benefit of allowing you to bounce from While to While with very little trouble. :)

---
Bringing you Pokemon, for your calculator.
Vectris
Ultralisk
avatar
Posted: 1 Oct 2008
18:42 GMT
Total Posts: 375
1->W
Repeat W=!1
getkey->K
If stuff:manipulate W
End

Lol repeat can be used in the same way, no big difference...
(=! is equals not)
tifreak8x
Administrator
avatar
Posted: 1 Oct 2008
20:12 GMT
Total Posts: 419
Again, NO IT CANNOT

Repeat is ALWAYS run at least ONCE. While is ONLY run when TRUE. There is a HUGE difference.

---
Bringing you Pokemon, for your calculator.
Vectris
Ultralisk
avatar
Posted: 2 Oct 2008
04:30 GMT
Total Posts: 375
Actually in this instance it can!

Since there is nothing in between 1->W and the command, even if it's while, it's still going to run because we didn't change W. Now if you added space in between the "declaration" of the varaible and the while/repeat, then while may do better since it will avoid it all together if W was changed somewhere in there.

But in that little code repeat does the same thing.
Zachary940
Wraith
avatar
Posted: 2 Oct 2008
07:40 GMT
Total Posts: 714
Like TiFreak said there is a huge difference between the two. Read what I say carefully. While will run as long as the statement is true. There for if W=10 and if you have a statement saying:

While W>=1
W-1->W
End

W now equals 0

That statement will run ONLY if W is greater then or equal to one.
There for Repeat runs until the statement is True. Meaning that it will run at least once. It has to.

Repeat W>=1
W-1->W
End

W now equals 9

The reason that it has to run once is so that it can prove that the statement is and will be false. It can be confusing I know, but it is good to know how. That way you can be sure you are using the right command to do the job.

TiFreak feel free to correct me if i messed something up or if I am confusing.

---
It is much easier to suggest solutions when you know nothing about the problem.
tifreak8x
Administrator
avatar
Posted: 2 Oct 2008
11:27 GMT
Total Posts: 419
The biggest difference is While check when it reaches a While statement to see if it is true/false, Repeat waits til it gets to its End statement to check if it is true/false, which is why it will ALWAYS run at least once.

---
Bringing you Pokemon, for your calculator.
darksideprogramming
Guardian
avatar
Posted: 3 Oct 2008
06:11 GMT
Total Posts: 1005
tifreak is indeed correct.
Vectris
Ultralisk
avatar
Posted: 3 Oct 2008
13:31 GMT
Total Posts: 375
Just thought I'd point out but that doesn't make While better. Perhaps the programmer wanted the code to run at least once before looping/ending. Then Repeat would be better. It all depends on the circumstances.





Portal | My Account | Register | Lost Password or Username | TOS | Disclaimer | Help | Site Search | File Archives Copyright © 2002-2019 CalcG.org