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.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
United-TI Archives -> TI-Basic
 
    » Goto page Previous  1, 2, 3 ... 9, 10, 11, 12, 13  Next
» View previous topic :: View next topic  
Author Message
Jutt


Advanced Newbie


Joined: 27 Jun 2004
Posts: 94

Posted: 27 Mar 2005 05:52:22 am    Post subject:

You can save 2 bytes by using
Repeat sum(K={21,45,105

instead of
Repeat K=21 or K=45 or K=105
Back to top
Arcane Wizard
`semi-hippie`


Super Elite (Last Title)


Joined: 02 Jun 2003
Posts: 8993

Posted: 27 Mar 2005 06:23:27 am    Post subject:

I was worried using a list would be too slow, but I guess it's not that bad, fixed, but it might need to be taken back out if one wants to add more graphical effects.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 27 Mar 2005 11:44:38 am    Post subject:

Repeat max(K={21,45,105 is better.

Edit: Arcane, in the code you edited at my suggestion you forgot to put
Ans+inString(Str0,",",Ans+1->X
I guess that's my fault since I forgot it first...


Last edited by Guest on 27 Mar 2005 12:16:35 pm; edited 1 time in total
Back to top
Arcane Wizard
`semi-hippie`


Super Elite (Last Title)


Joined: 02 Jun 2003
Posts: 8993

Posted: 27 Mar 2005 12:18:49 pm    Post subject:

Ah, thanks, I fixed that and changed sum( to max(.

Is max( faster?


Last edited by Guest on 27 Mar 2005 12:19:33 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 27 Mar 2005 12:24:17 pm    Post subject:

Slightly... I checked it and it's about 17% faster for a list of 0's and 1's.

Edit: on an 83+ you can do

Code:
Text(-1,0,50-3X,sub(Str0,1,X-1
to draw the title centered and in large font. It's a bit harder to center it in the small font.

Last edited by Guest on 27 Mar 2005 12:34:02 pm; edited 1 time in total
Back to top
Arcane Wizard
`semi-hippie`


Super Elite (Last Title)


Joined: 02 Jun 2003
Posts: 8993

Posted: 28 Mar 2005 06:15:01 am    Post subject:

There wasn't any reason left to store the length of the string to L, so I got rid of that.

"MENU TITLE,OPTION 1,OPTION 2,OPTION 3,OPTION 4,OPTION 5,OPTION 6,OPTION 7,OPTION 8,->Str0 //make sure to end the string with a ,
inString(Ans,",->X //get the length of the title
Delvar A0->Ø //A will be a temp var for X and Ø will hold the position to draw the option at
Text(0,0,sub(Str0,1,X-1 //draw the title

While X<length(Str0 //loop through all the options
X->A //remember current option offset (the "," before the current option) A+1 is the first character of the current optoin
Ans+inString(Str0,",",Ans+1->X //store the position of the next comma in X
Ø+7->Ø //next line
Text(Ans,10,sub(Str0,A+1,X-A-1 //draw option
End

7->X //starting position of the cursor
Repeat max(K={21,45,105 //untill 2nd, clear, or enter is pressed
getKey->K
If Ans:Text(X,0,"_ _ _ _ //erase the cursor if a key was pressed
X+7((Ans=34 and X<Ø)-(Ans=25 and X>7->X //move the cursor
Text(Ans,0,"> //draw the cursor
End

X/7 //return which option

I'm also thinking of combining the two loops into one, somehow.


Last edited by Guest on 28 Mar 2005 06:15:33 am; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 28 Mar 2005 10:28:20 am    Post subject:

You mean the Repeat loop and the While loop? Somehow, that doesn't sound feasible to me. Also, some people may want to modify the routine to display the options manually, if they only have one menu in a game.

also, some optimization:

Code:
1->X  //starting position of the cursor
Repeat max(K={21,45,105 //until 2nd, clear, or enter is pressed
getKey->K
If Ans:Text(7X,0,"_ _ _ //erase the cursor if a key was pressed
X+(Ans=34 and 7X<Ø)-(Ans=25 and X>1->X //move the cursor
Text(7Ans,0,"> //draw the cursor
End
//Ans already contains selected option
Back to top
appleyardsk8


Newbie


Joined: 06 Apr 2005
Posts: 11

Posted: 05 May 2005 06:32:17 pm    Post subject:

Here's a Highscore program i recently made for my upcoming game. This is my first attempt at manipulating strings in such a complex way. In the past i used a different string for every name, but now that i am focusing more on efficiency, that method seems unacceptable.This is what i came up with (Write now its set-up to hold 6 rankings, but that probably wouldnt be difficult to change):


Code:
VARIABLES

Str7= "1name2name3name4name5name6name"
S=Score
L*high= List of high scores
R=Variable to check that this subroutine was activated by the game, and not by my menu program which calls it to view highscores only (note-The game stores it as The first rand number in the seed # of the player's score)



Code:
:S->Rand                                                     ;Set Rand seed
:If R=rand and S>L*high(6):then                          ;Check For R and Applicable Score
:0->R                                                          ;reset R
:"123456"->str8                                            ;set ranking string
:S->L*high(6)                                               ;insert score in score list
:SortD(L*high                                               ;sort score list
:For(A,1,6                                                    ;
:If L*high(A=S:A->Z                                    ;find player's ranking
:end                                                            ;
:Clrhome                                                     ;
:Disp "HIGHSCORE!                                      ;
:Input "NAME?(NO DIGITS)",Str1                           ;Store name to str1(numbers throw off my routine)
:sub(Str8,Z,1->Str0                                     ;Convert ranking to string
:sub(Str7,1,instring(str7,Str0))+Str1->Str1           ;Store Higher ranked names and player name to string
:While Z DOES NOT EQUAL  6                             ;loop for adding lower ranked names
:Z+1->Z                                                    ;increase rank number
:sub(Str8,Z,1                                              ;change rank to temp string
:Str1+Ans+sub(Str7,instring(Str7,Str0)+1,    
instring(Str7,Ans)-instring(str7,Str0)-1->Str1      ;add next player's new rank# and name to existing string
:sub(str8,Z,1->Str0                                    ;necessary for the command above to work correctly, remembers previous player's ranking
:End                                                          ;
:Str1->Str7                                                ;store built string to permanent string
:Delvar Str1Delvar Str8Delvar Str0                      ;delete temporary strings
:End                                                          ;
.                                                               \
.                                                               ;Set up high score table to your liking
.                                                               /
:1->B                                                        ;counting variable
:"123456_"->Str8                                      ;set ranking string (kind of redundant)
:For(A,16,51,7                                           ;output loop incrementing with y cordinate
:Text(A,23,"-"                                           ;Score\name seperator
:Text(A,5,L*high(B),"00"                            ;output score
:sub(Str8,B,1->Str0                                  ;put rank # in string
:sub(Str8,B+1,1                                        ;put next rank # in string
:If B DOES NOT EQUAL 6                           ;the following output doesnt work for the last ranked name
:Text(A,29,sub(Str7,instring(Str7,Srt0)+1,  
instring(Str7,Ans)-Instring(Str7,Str0)-1           ;Output name
:1+B->B                                                  ;move on to next player
:end                                                        ;
:Text(51,29,sub(Str7,instring(Str7,Str0)+1,
length(Str7)-instring(Str7,Str0                           ;output last ranked player name
:Delvar Str8Delvar Str0                                ;delete temp strings
:Pause                                               ;enjoy :>
:Clrdraw                                              ;clear


Feel free to use to your likings, but my main reason for posting this is for help in optimizing it. Any Ideas?
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 05 May 2005 06:41:39 pm    Post subject:

Yes, see this post ;-)

I didn't know as much as I do now about 89 programming though, time to optimize that section.

TI-89 / 92 / 92+:

For compatibility purposes ("window" width):

Code:
getConfg()[14]->width


there can be as many high scores, of any length, as you like, but I assume they fit. To circumcise any high score string do as I did in the 83+ version:

Code:
left(string+" #-1 spaces", #) -> string
where # is the maximum length of the string.

it's much easier to have the high score names first then all the scores (I will have 5 scores for simplicity):


Code:
{"Sir Robin!","is still!","the most selfish!","SOB!", "in existence!",.824358770094991,100000,90000,80000,70000,60000} -> hiscores


First we separate this into 2 lists:


Code:
left(hiscores,5) -> names
right(hiscores,5) -> scores


to add in a high score:


Code:
If score>scores[dim(scores)] Then
score -> scores[dim(scores)]
name -> names[dim(names)]
SortA scores,names
EndIf


see how easy that was? but, on the other hand, displaying is harder. We have to output each name and score by hand.


Code:
ClrIO
Output 0,width/2-33,"High Scores"
For i,1,5
Output 8*i,0,names[i]
Output 8*i,width-6*int(log(10scores[i])+1),scores[i]
EndFor


then putting names[] and scores[] back together into one list, this time with an all-new tamper guard:

Code:
RandSeed norm([scores])
names->hiscores
rand()->hiscores[6]
augment(hiscores,scores)->hiscores


oh, and I almost forgot, CHECKING the tamper guard:


Code:
RandSeed norm([scores])
If rand() != hiscores[6] Then
Text "YOU MESSED WITH MY HISCORES!!!"
{"Sir Robin!","is still!","the most selfish!","SOB!", "in existence!",.824358770094991,100000,90000,80000,70000,60000} -> hiscores
EndIf


Last edited by Guest on 05 May 2005 07:01:12 pm; edited 1 time in total
Back to top
appleyardsk8


Newbie


Joined: 06 Apr 2005
Posts: 11

Posted: 05 May 2005 09:15:56 pm    Post subject:

something in your code from your older post doesnt work right. It doesnt extract the names correctly from the string.

(my bad about taking so long to fix this sir robin)


Last edited by Guest on 01 Jun 2005 12:44:57 am; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 06 May 2005 03:24:23 pm    Post subject:

My code works nearly perfectly, except for some reason I store the wrong thing to K. It should be:

[font="Fixedsys"]
{ -> L6 //start out with an empty list
For(I,1,7 //7 high scores
DelVar J
16I-4 -> K //K=furthest left the Ith high score can start
While " "=sub(Str0,K+J,1
J+1->J
End //Str0[K+J] is the first character that's not a space
expr(sub(Str0,K+J,5-J -> L6(I //there are 5-J digits in the hi-score, and it starts at K+J
End


I'll go back and fix it in the original post.
Back to top
elfprince13
Retired


Super Elite (Last Title)


Joined: 11 Apr 2005
Posts: 3500

Posted: 27 May 2005 07:41:43 pm    Post subject:

you also missed this:

Code:
Text(-1,1,1"Hi
displays large font

Code:
Text(1,1,"Hi
displays small font

You could also use Omnicalc if you had a link cable
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 27 May 2005 08:23:18 pm    Post subject:

Here is a method to search through a list for a specific number and then return the number's position in the list.

[font="courier new"]max(seq(X(value=listname(X)),X,start,dim(listname


This is very much like the [font="courier new"]inString( function, as advertised below:

[font="courier new"]inString("527946","9",2 // Output is 4

[font="courier new"]{5,2,7,9,4,6:max(seq(X(9=Ans(X)),X,2,6 // Same output

Both give the answer of 4 because that is the number's position in both types of data.

[ E x t r a ]

To find the position of the smallest number not equal to zero:

[font="courier new"]min(seq(Xlistname(X)+E[font="courier new"]9not(listname(X)),X,start,dim(listname

Last edited by Guest on 27 May 2005 08:34:13 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 29 May 2005 08:02:36 pm    Post subject:

If the value you're looking for occurs more than once in the list, that will return the index of the last occurrence, making it slightly different from inString(.

Some optimization (only works when you start at the beginning of the list though):

max((value=listname)seq(I,I,1,dim(listname

to save calculating the comparison every single time you loop through the seq(.

If you want to find the first occurence, do:

-min((value=listname)seq(-I,I,1,dim(listname
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 29 May 2005 08:38:49 pm    Post subject:

I was waiting for someone to point out that occurrence error. Smile This came around when I needed to pinpoint numbers inside of a matrix. Not surprisingly, it called for a few interestingly long lines of code. I think the outcome of what I'm using it for will be worth it.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 29 May 2005 08:42:01 pm    Post subject:

This would probably be one of the cases where using a list instead of a matrix would work better. Wink
Back to top
AlienCC
Creative Receptacle!


Know-It-All


Joined: 24 May 2003
Posts: 1927

Posted: 29 May 2005 10:08:32 pm    Post subject:

Of course, routines are very much welcome in the Downloads section of this website.

--AlienCC
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 29 May 2005 10:42:49 pm    Post subject:

Because I've just posted this over at MaxCoderz forum:

Text input routine -

Code:
Repeat Ans>40 and Ans<94:getKey:End
sub("ABC  DEFGHIJKLMNOPQRSTUVWXYZ",Ans-20-5int(.1Ans),1


Definitely not worth an upload, but might be useful.
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 29 May 2005 11:49:09 pm    Post subject:

I've noticed that while using [font="courier new"]seq(, the calculator can still interpret keypresses and store them to getKey. Based off that idea, here's yet another simple password routine—The keys should be typed in the correct sequence before time expires, and the password is "HELLO" in this case:

[font="courier new"]ClrHome
0→dim(L1
seq(getKey,X,1,200→L2
Disp "Validating...
For(A,1,dim(L2
L2(A
If Ans
Ans→L1(1+dim(L1
End
If 5=dim(L1
If max(L1≠{55,52,64,64,72
Stop
DelVar L1DelVar L2"Success!


Last edited by Guest on 30 May 2005 12:22:02 am; edited 1 time in total
Back to top
appleyardsk8


Newbie


Joined: 06 Apr 2005
Posts: 11

Posted: 01 Jun 2005 01:08:42 am    Post subject:

"If-then statements work faster than if statements"

I dont remember exactly where i read this little tidbit, but im sure it was somewhere in this basic forum ( i got lazy searching for the quote, ill find it later). This doest make sense to me. if the calculater activates an if-then statement, then it has to use some memory to look for the end command. Its this fact that causes every beginner's game's game speed to decay over time (ahhh, the good ol goto statements). It seems to me that an if statement should not have to do this, because no matter what happens, its only going to activate the next line, or not activate it. can anybody back this statement up or disprove it, so i can have my peace of mind back? (ok, its not really bothering me that much, but it has been bugging me every time i go to use if statements in my progy's Laughing)


Last edited by Guest on 01 Jun 2005 01:10:59 am; edited 1 time in total
Back to top
Display posts from previous:   
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
    » Goto page Previous  1, 2, 3 ... 9, 10, 11, 12, 13  Next
» View previous topic :: View next topic  
Page 10 of 13 » All times are UTC - 5 Hours

 

Advertisement