This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

TI-Basic => TI-BASIC
 » Goto page Previous  1, 2, 3 ... 10, 11, 12, 13  Next
Author Message
leofox
INF student

Super Elite (Last Title)

Joined: 11 Apr 2004
Posts: 3562

 Posted: 01 Jun 2005 08:49:37 am    Post subject: what you say makes sense, but for some reason, If-Then-End statements are a lot faster than If. I think it's that if statements have to look for linebreaks. Since linebreaks can be hard-returns or ":", it has to look for 2 things, in comparision to just the End for If-Then-End. If you don't believe it, you can always try it on your calc and time it: Code: ```0->X For(i,1,1000 If X=0 :         this empty line is important! If it's not there, it will see the End there as part of the if statement! End``` Code: ```0->X For(i,1,1000 If X=0 Then End End``` You can try again with different values for X. You can see that If is very slow if the test is false.
DarkerLine
ceci n'est pas une |

Super Elite (Last Title)

Joined: 04 Nov 2003
Posts: 8328

 Posted: 01 Jun 2005 10:40:46 am    Post subject: Your explanation makes sense therefore it's probably wrong. There's very little about TI-Basic that makes any kind of regular sense. However, when the test is true, the If vs. If-Then difference becomes smaller and actually reverses.
appleyardsk8

Newbie

Joined: 06 Apr 2005
Posts: 11

 Posted: 01 Jun 2005 05:13:22 pm    Post subject: So if statements in loops should only be used if it will return true for most of a program's execution? WOW... that means that my hit detection for all my games, which looks like this: If (enemie gets hit) prgm(blow enemy up) are all gonna have to go, because most of the time they return false, which must slow down my game more than If (enemie gets hit):Then . . . (blow enemy up) . . . end wait a minute. Leofox, your test tests an if-then statement with an end immediatly after the then. if i use alot of lines (up to fifteen) between my if-then statements, then will this work faster than using an if-subroutine command, like the one shown above? Keep in mind, i'm talking about an argument that will usually be false. Now I'm just thinking on my keyboard, but maybe an if-then-subroutine-end statement would be the fastest. EDIT I decided to test this out a little. This is my setup: IF-THEN :5->x :For(A,1,100 :If X: Then :disp 1 :disp 2 :disp 3 :disp 4 :disp 5 :disp 6 :disp 7 :disp 8 :clrhome :end :end IF-SUBROUTINE :5->x :For(A,1,100 :If x:prgmTEST :end IF-THEN-SUBROUTINE-END :5->x :For(A,1,100 :If x:then :prgmTEST :end :end PRGMTEST :disp 1 :disp 2 :disp 3 :disp 4 :disp 5 :disp 6 :disp 7 :disp 8 :clrhome This tested for speed when the statements returned true. here are my results: IF-THEN - 23.8 sec IF-SUB - 52.2 IF-THEN-SUB - 51.2 What i really wanted to test for, however, was speed when the statements were false. So i changed the program to store 0 to x at the beginning, and then changed the for statement to run to 1000. These are my results: IF-THEN - 14.7;14.3 IF-SUB - 83.4 (ouch!, this is what ive been using!) IF-THEN-SUB - 12.8;12.8 I'm going to test some more to see if one of the two close ones overtake one or the other when more disp lines are added, but this has already helped me out a shitload!Last edited by Guest on 01 Jun 2005 10:38:22 pm; edited 1 time in total
Everett Martin

Newbie

Joined: 18 Jul 2005
Posts: 42

 Posted: 28 Aug 2005 04:50:01 pm    Post subject: Here is my source code for a menu, I understand this one more than I do any of those other menu codes, any optimizations and comments welcomed. Code: ```PROGRAM:MENU :CoordOff :GridOff :AxesOff :LabelOff :ExprOff :ClrDraw :10 -> B :Lbl A :Horizontal 52 :Text(0,0,"MAIN MENU TITLE :Title(10,11,"OPTION 1 :Text(18,11,"OPTION 2 :Text(26,11,"OPTION 3 :Text(34,11,"OPTION 4 :Text(42,11,"EXIT PROGRAM :While 1 :getKey -> A :While A=25 and A=34 and A=105 :getKey -> A :End :Text(B,0,">> :Text(B,87,"<< :If A=34:Then :If B /= 42:Then :Text(B,0,"        // 7 spaces :Text(B,87,"       // 7 spaces :B+8 -> B :Goto A :Else:Text(B,0,"   // 7 spaces :Text(B,87,"       // 7 spaces :10 -> B :Goto A :End :End :If A=25:Then :If B /= 10:Then :Text(B,0,"        // 7 spaces :Text(B,87,"       // 7 spaces :B-8 -> B :Goto A :Else:Text(B,0,"   // 7 spaces :Text(B,87,"       // 7 spaces :42 -> B :Goto A :End :End :If A=105:Then :If B=10:Then :ClrDraw :Text(0,0,"OPTION 1 :Pause :ClrDraw :Goto A :End :If B=18:Then :ClrDraw :Text(0,0,"OPTION 2 :Pause :ClrDraw :Goto A :End :If B=26:Then :ClrDraw :Text(0,0,"OPTION 3 :Pause :ClrDraw :Goto A :If B=34:Then :ClrDraw :Text(0,0,"OPTION 4 :Pause :ClrDraw :Goto A :End :If B=42:Then :ClrDraw :Text(0,0,"EXIT OPTION-PRESS ENTER :Pause :ClrDraw :Goto EX :End :End :End :Lbl EX```Last edited by Guest on 28 Aug 2005 06:18:51 pm; edited 1 time in total
Weregoose
Authentic INTJ

Super Elite (Last Title)

Joined: 25 Nov 2004
Posts: 3976

 Posted: 28 Aug 2005 06:13:45 pm    Post subject: Some initial pointers before we get into lengthy optimization: [font="courier new"]CoordOff only effects the graph screen in a program during [font="courier new"]Input without arguments. [font="courier new"]LabelOff—If the axes aren't turned on, this won't be turned on either. [font="courier new"]ExprOff is good only for removing the expression in case of a Calc (F4) or Trace (F5). [font="courier new"]Horizontal depends on the window dimensions to go where you want it to. [font="courier new"]FnOff should be used to turn off all graphing functions beforehand. [font="courier new"]Goto inside of conditional statements? Augh! Memory leak imminent! (Rewrite required) It looks as though a new [font="courier new"]If-Then-Else-End statement is needed for the display of each additional option. It'd be better to restructure the program for flexibility (seamless transfer of menu objects) so replication of the code between programs is faster and easier. Hmm, you wrote [font="courier new"]Title(). Did you mean [font="courier new"]Text? Finally, considering the number of times seven spaces occur, you can store them to a string at the beginning of the program for later use, saving you a total of 36 bytes. A good rewrite should remove the need to use it multiple times anyway. Here's an overhaul of the code—A bit clunky, I think: Code: ```[font="courier new"]StoreGDB 1 FnOff ClrHome ClrDraw GridOff AxesOff PlotsOff 0→Ymin 9→Ymax [color=red]",MILK,EGGS,BREAD,FRUIT,CHEESE,DONE,→Str1 // Feel free to edit these[/color] 0→dim(L1[/font] While inString(Str1,",",Ans+1 1+inString(Str1,",",Ans+1→L1(1+dim(L1 End 8→B Ans→C 8dim(L1)-8→D Horizontal 8 [color=red]Text(0,0,"SHOPPING CHECKLIST[/color] For(A,1,dim(L1)-1 Text(8A,11,sub(Str1,L1(A),L1(A+1)-1-L1(A End Repeat B8ֿ¹+1=dim(L1 Repeat 42=abs(A-63 "░░░░░░░ // 7 spaces Text(C,0,Ans Text(C,87,"Ans Text(B,0,">> Text(B,0,"<< B→C Repeat Ans getKey→A End If Ans=45 D→B B+8((Ans=34)-(Ans=25 Ans+D((Ans<8)-(Ans>D→B End Ans8ֿ¹ If Ans+1≠dim(L1 Then Disp sub(Str1,L1(Ans),L1(Ans+1)-1-L1(Ans Repeat getKey End End ClrHome End ClrDraw RecallGDB 1``` When you change the contents of Str1, make sure that it's ranging from one to seven items, with one comma on each side of an element (including the side elements). The number of items in the string will correspond to the cursor boundaries, as well as the loop which results from passing over them. Pressing CLEAR jumps to the last item, which will always be a "quit" item, so adjust that name accordingly. Other than all that, I suppose this works exactly as the default menu system would. Please, feel free to add anything else. Example Menus Famous Constants φ Golden Ratio γ Euler's Constat α Feigenbaum alpha K Khinchin constant G Catalan constant Back to Home Phone Book 555-2847 Deborah Allen 555-4521 Toni Basil 555-8453 Rosalind Chao 555-9415 Tommy Collins Hang Up Error:Domain QuitLast edited by Guest on 29 Aug 2005 12:55:10 am; edited 1 time in total
alexrudd
pm me if you read this

Bandwidth Hog

Joined: 06 Oct 2004
Posts: 2335

 Posted: 28 Aug 2005 10:52:18 pm    Post subject: Code: ```:getKey->A :While A=25 and A=34 and A=105 :getKey -> A :End```Think about that one for a while. How about Code: ```:Repeat A=25 or A=34 or A=105 :getKey->A :End```Even better would be to use Ans.Last edited by Guest on 28 Aug 2005 10:55:23 pm; edited 1 time in total
necro

Joined: 09 Apr 2005
Posts: 278

 Posted: 15 Sep 2005 05:06:24 pm    Post subject: appleyardsk8 wrote:    This tested for speed when the statements returned true. here are my results: IF-THEN  -  23.8 sec IF-SUB  -  52.2 IF-THEN-SUB  -  51.2     What i really wanted to test for, however, was speed when the statements were false. So i changed the program to store 0 to x at the beginning, and then changed the for statement to run to 1000. These are my results: IF-THEN  -  14.7;14.3 IF-SUB  -  83.4  (ouch!, this is what ive been using!) IF-THEN-SUB  -  12.8;12.8       I'm going to test some more to see if one of the two close ones overtake one or the other when more disp lines are added, but this has already helped me out a shitload! [post="51280"]<{POST_SNAPBACK}>[/post] WHAT!?!?!?!?!...well, this certainley will be a nice optimisationLast edited by Guest on 15 Sep 2005 05:10:08 pm; edited 1 time in total
MissingIntellect

Member

Joined: 01 Jun 2004
Posts: 227

 Posted: 22 Sep 2005 04:08:33 pm    Post subject: alexrudd wrote:Code: ```:getKey->A :While A=25 and A=34 and A=105 :getKey -> A :End```Think about that one for a while. How about Code: ```:Repeat A=25 or A=34 or A=105 :getKey->A :End```Even better would be to use Ans. [post="55007"]<{POST_SNAPBACK}>[/post] Code: ```Repeat max(getKey={25,34,105 End```
alexrudd
pm me if you read this

Bandwidth Hog

Joined: 06 Oct 2004
Posts: 2335

 Posted: 22 Sep 2005 06:56:30 pm    Post subject: Great idea, but it doesn't store the value of getKey for further use.
leofox
INF student

Super Elite (Last Title)

Joined: 11 Apr 2004
Posts: 3562

 Posted: 23 Sep 2005 06:45:28 am    Post subject: Repeat Ans max(getKey={25,34,105 End ?
DarkerLine
ceci n'est pas une |

Super Elite (Last Title)

Joined: 04 Nov 2003
Posts: 8328

 Posted: 23 Sep 2005 04:08:13 pm    Post subject: It works for a delay until the keys are pressed, but you don't ever find out which one was pressed because Ans is always 1 when you exit. Code: ```Repeat max(Ans={25,34,105 getKey End```It's the same size as yours, too.
MissingIntellect

Member

Joined: 01 Jun 2004
Posts: 227

 Posted: 23 Sep 2005 06:03:38 pm    Post subject: Sir Robin wrote:It works for a delay until the keys are pressed, but you don't ever find out which one was pressed because Ans is always 1 when you exit. Code: ```Repeat max(Ans={25,34,105 getKey End```It's the same size as yours, too.  [post="56875"]<{POST_SNAPBACK}>[/post] Err, I misunderstood what it was meant for.Last edited by Guest on 23 Sep 2005 10:16:31 pm; edited 1 time in total
taco

Newbie

Joined: 21 Sep 2005
Posts: 35

 Posted: 25 Sep 2005 06:35:48 pm    Post subject: Well I don't know if that has been said, but all the first program posted in here (by Arcane Wizard) did was make infinite 0's in the list. :\
DarkerLine
ceci n'est pas une |

Super Elite (Last Title)

Joined: 04 Nov 2003
Posts: 8328

 Posted: 25 Sep 2005 07:10:13 pm    Post subject: Read the one on the 9th page then, I'm pretty sure I've tested that myself.
Arcane Wizard
`semi-hippie`

Super Elite (Last Title)

Joined: 02 Jun 2003
Posts: 8993

 Posted: 26 Sep 2005 04:54:02 am    Post subject: taco wrote:Well I don't know if that has been said, but all the first program posted in here (by Arcane Wizard) did was make infinite 0's in the list. :\ [post="57050"]<{POST_SNAPBACK}>[/post]Though I'm sure that one works if you copy it correctly , look for the improved version here, on page 10.Last edited by Guest on 26 Sep 2005 05:16:29 am; edited 1 time in total
SilverCalcKnight
|_

Active Member

Joined: 15 Nov 2005
Posts: 577

 Posted: 05 Jan 2006 05:12:05 pm    Post subject: This may have been posted here already, but: Collision detection routine + map save (i.e. level parser) Just make a matrix with {8,16}-->dim([ A ] , then store where you want objects on the screen to their respective coordinates, but use a different number for a different character. Then write this: Code: ```:For(Y,1,16 :If [ A ](X,Y)=1 :Output(X,Y,"A :If [ A ](X,Y)=2 :Output(X,Y,"B :End :End :5-->X:5-->Y :Output(X,Y,"P :Lbl 1 :getKey-->K :While K=0 :getKey-->K :End :If K=24 and Y>2 and [ A ](X,Y-1)=0:Then :Y-1-->Y :Output(X,Y+1,"_ :Output(X,Y,"P :End :If K=25 and X>2 and [ A ](X-1,Y)=0:Then :X-1-->X :Output(X+1,Y,"_ :Output(X,Y,"P :End :If K=26 and Y<15 and [ A ](X,Y+1)=0:Then :Y+1-->Y :Output(X,Y-1,"_ :Output(X,Y,"P :End :If K=34 and X<7 and [ A ](X+1,Y)=0:Then :X+1-->X :Output(X-1,Y,"_ :Output(X,Y,"P :End :If K=105:Then :9-->[ A ](X,Y) :Stop :End :Goto 1``` You can even do the matrix storing from within a program, but I didn't feel like writing it out. (it is a huge line, trust me )
Liazon
title goes here

Bandwidth Hog

Joined: 01 Nov 2005
Posts: 2007

 Posted: 05 Jan 2006 05:14:32 pm    Post subject: You could probably even use a string to do tilemapping, but I think finding the offset for the sub()/mid() based off of grid coordinates would be really annoying.
SilverCalcKnight
|_

Active Member

Joined: 15 Nov 2005
Posts: 577

 Posted: 05 Jan 2006 05:34:35 pm    Post subject: Yes, you can. I even use a string to output the border (that is,the border of the screen of the game I am working on),but nothing else, due to the reason you have stated.
WikiGuru

Elite

Joined: 15 Sep 2005
Posts: 923

 Posted: 10 Jul 2006 12:00:52 pm    Post subject: Sorry if this is already in here, but I'm too lazy to read through all the posts to see if it is. Sort of a pause/Getkey-routine. Also allows you to press 2nd/Alpha. Only 4 bytes! Code: `RepeatGetkey:End` Okay, it's not really a great routine, but it is smaller than Code: `Repeat ANS:Getkey:End`, and acts exactly the same way (almost).
Weregoose
Authentic INTJ

Super Elite (Last Title)

Joined: 25 Nov 2004
Posts: 3976

 Posted: 10 Jul 2006 01:17:33 pm    Post subject: 1 | 2 | 3
 Display posts from previous: All Posts Oldest FirstNewest First
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.

»
 » Goto page Previous  1, 2, 3 ... 10, 11, 12, 13  Next Page 11 of 13 » All times are UTC - 5 Hours