Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
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. 68k Calculator Basic => TI-BASIC
Author Message
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 29 Mar 2006 04:03:40 pm    Post subject:

If you have any routines to share for the TI-89 series calculators, post them here rather than in the main TI-Basic forum. Only post routines here if you don't mind people using it in their own programs, possibly without giving you credit.

I'll start off with a high score routine I already posted in the other topic.

The main difference between the TI-89, TI-92, etc. is the window size (specifically, the window width; the height shouldn't matter as much for display). getConfg() returns a number of parameters that include the width of the screen (the 14th element of the list). We won't need this until much later on though. Still, let's go ahead and store it to a variable:

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:
{"DarkerLine","DarkerLine","DarkerLine","DarkerLine", "DarkerLine",.824358770094991,100000,90000,80000,70000,60000} -> hiscores


First we separate this into 2 lists:

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


Of course, we could keep the names and scores in two separate lists all the time (and presumably a third variable for the tamper guard). I prefer this way, since I find keeping a lot of variables around after the program exits complicated (for both the user and the programmer).

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!!!"
{"DarkerLine","DarkerLine","DarkerLine","DarkerLine", "DarkerLine",.824358770094991,100000,90000,80000,70000,60000} -> hiscores
EndIf


Warning: this tamper guard uses random numbers every time you check it or change it. You might want to do something like RandSeed startTmr() so the random number generator doesn't always return the same things.


Last edited by Guest on 10 Aug 2008 07:01:04 pm; edited 1 time in total
Back to top
IAmACalculator
In a state of quasi-hiatus


Know-It-All


Joined: 21 Oct 2005
Posts: 1571

Posted: 29 Mar 2006 08:14:00 pm    Post subject:

I was feeling the lack of a randint() command on the 89, so I came up with this.

Code:
randint(boundone,boundtwo)
rand(abs(when(boundone<boundtwo,boundone-boundtwo,boundtwo-boundone)-
  1))+when(boundone<boundtwo,boundone,boundtwo)-1


Last edited by Guest on 30 Mar 2006 11:58:38 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: 29 Mar 2006 09:06:51 pm    Post subject:

Not that I want to criticize the first contributor to the topic, but what you're essentially doing with those when() statements is rewriting the abs() and min() functions. By using those functions, you can make the code significantly smaller:

Code:
randint(a,b)
rand(abs(a-b)+1)+min(a,b)-1
Also, you don't have to be nice to the user. Be mean, and make him put the numbers in the right order! That would shave off an additional few bytes Wink
Back to top
IAmACalculator
In a state of quasi-hiatus


Know-It-All


Joined: 21 Oct 2005
Posts: 1571

Posted: 29 Mar 2006 11:39:45 pm    Post subject:

I'm just not good at optimizing. A little constructive criticism is always good for me. Laughing
Back to top
sexybear979


Newbie


Joined: 27 Mar 2006
Posts: 28

Posted: 30 Mar 2006 03:14:53 pm    Post subject:

I've got a few lines for a preloader. However useless and timewasting a preloader may be, it does make your program look much more official.


Code:
0->b
ClrDraw
PxlText "Please Wait...",32,42
PxlText "% Loaded",42,59
For a,0,158
PxlVert a,-1
PxlText string(floor(a*(100/159))),42,44
EndFor
ClrDraw


You can then insert your program in afterwards
Back to top
IAmACalculator
In a state of quasi-hiatus


Know-It-All


Joined: 21 Oct 2005
Posts: 1571

Posted: 31 Mar 2006 07:46:00 am    Post subject:

Heh. I had almost that same code for my annoying fortune teller program. I've got to finish that thing some day...
Back to top
sexybear979


Newbie


Joined: 27 Mar 2006
Posts: 28

Posted: 01 Apr 2006 01:05:13 am    Post subject:

Two routines:

One, a screen inverter:

Code:
Local a
For a,0,76
PxlHorz a,-1
EndFor


And two, a graph screen clearer:


Code:
Local a
For a,1,99
Delvar #("y"&a)
Endfor


Short but sweet, nothing original, but certainly useful
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 01 Apr 2006 03:36:01 pm    Post subject:

For the last one, I think I prefer FnOff, since it doesn't delete the actual variables. And is shorter. Unless it's the goal of the program to delete the variables, rather than achieve temporary freedom and control over the graph screen.

Last edited by Guest on 01 Apr 2006 03:36:46 pm; edited 1 time in total
Back to top
sexybear979


Newbie


Joined: 27 Mar 2006
Posts: 28

Posted: 02 Apr 2006 10:48:22 pm    Post subject:

DarkerLine wrote:
For the last one, I think I prefer FnOff, since it doesn't delete the actual variables. And is shorter. Unless it's the goal of the program to delete the variables, rather than achieve temporary freedom and control over the graph screen.
[post="73763"]<{POST_SNAPBACK}>[/post]


You're right, FnOff is better, I guess I haven't used that function in a while (multiple years).

Another short simple routine to return an assigned number for a pressed key:

Loop
getKey()⇒key
If key>0 Then
Disp key
EndIf
EndLoop
Back to top
jimbauwens


Newbie


Joined: 27 May 2007
Posts: 3

Posted: 21 Jul 2007 02:27:52 pm    Post subject:

Some graphical routines :

Display bold text:
Quote:
BOLD(textt,y,x)
Prgm
local tp
pxltext textt,y,x
stopic tp,y,x,dim(textt)*6,8
rclpic tp,y,x+1
Endprgm
Usage : bold("Your text",y,x)


Display italic text:
Quote:
italic(textt,y,x)
Prgm
local tp
pxltext textt,y,x
stopic tp,y,x,dim(textt)*6+1,4
xorpic tp,y,x
rclpic tp,y,x+1
Endprgm
Usage : italic("Your text",y,x)


Display underlined text:
Quote:
underline(textt,y,x)
Prgm
pxlline y+8,x+dim(textt)*6
Endprgm
Usage : underline("Your text",y,x)

--

Function that returns pressed key :

Quote:
keywait()
Func
local key
0->key
while key=0
getkey()->key
endwhile
return key
endfunc
Usage : run keywait() and press an key, it will return the keycode.
It is verry useful if you want to know the keycodes


Last edited by Guest on 21 Jul 2007 02:29:15 pm; edited 1 time in total
Back to top
angel14995


Member


Joined: 13 Oct 2007
Posts: 181

Posted: 07 Jul 2009 06:33:27 am    Post subject:

Hey all!

Sorry for lurking so much recently, I've been having other things to do. Anyways...

For the 68k calculators, is there a way to change a list's size, say from 10 to 8 and vice versa? I'm working on a deck shuffling/drawing set of routines, and TI seems to have taken away one of my favorite commands from the 83 series. (X -> dim(L1))

Also, is there a string length method? I mean, like if the input was length("hello world"), it would return 11.

Thanks!
Back to top
IAmACalculator
In a state of quasi-hiatus


Know-It-All


Joined: 21 Oct 2005
Posts: 1571

Posted: 07 Jul 2009 06:41:51 am    Post subject:

I dunno about the list size thing, but to find string lengths, just use the dim( command, e.g. dim("ABC123") returns 6.

Last edited by Guest on 05 Jul 2010 08:25:56 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: 07 Jul 2009 03:45:33 pm    Post subject:

You can't downsize a list in the same way as on the TI-83+. But you can use the left(), right(), and mid() commands to take parts of a list, which should be good enough. If you just want the first 5 elements of a list, left(list,5)→list should do the trick.

Last edited by Guest on 05 Jul 2010 08:26:11 am; edited 1 time in total
Back to top
angel14995


Member


Joined: 13 Oct 2007
Posts: 181

Posted: 08 Jul 2009 11:56:43 pm    Post subject:

Yeah, that's gonna be a problem...

See, I am working with a deck system, and I need to be able to do randoms from the specific deck list, and then either remove or make it so that it works strange... bah.....

Anyways, thanks. I'll probably rework my draw and shuffle commands now to use those three commands.
Back to top
IAmACalculator
In a state of quasi-hiatus


Know-It-All


Joined: 21 Oct 2005
Posts: 1571

Posted: 09 Jul 2009 07:08:03 pm    Post subject:

It's not too hard to remove a specific element of a list. Where n is the index of the item to remove and l is the list itself:

Define rem(list,n)=augment(left(list,n-1),right(list,dim(list)-n))

I ran it through a couple of simple tests, and I think that it should work. Note that left({1,2,3},0) returns an empty list.


Last edited by Guest on 05 Jul 2010 08:26:30 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: 10 Jul 2009 01:34:30 pm    Post subject:

Or even this:

Define rem(list,n) = rotate(mid(rotate(list,n),2),-n)

I haven't tested this at all, so it may crash or it may be slower than the augment() method, but it's an alternative. Plus, it also works on strings (assuming it does work). Edit: it works, but the result is 0-indexed rather than 1-indexed, so you might try rotate(mid(rotate(list,n-1),2),1-n).

P. S. IAmACalculator, keep in mind that l and 1 look exactly the same in that font.


Last edited by Guest on 05 Jul 2010 08:26:46 am; edited 1 time in total
Back to top
IAmACalculator
In a state of quasi-hiatus


Know-It-All


Joined: 21 Oct 2005
Posts: 1571

Posted: 13 Jul 2009 07:52:24 am    Post subject:

Ooh, good catch. Editing for legibility!

Mine works on strings too, with a slight modification:

Define rem(list,n)=left(list,n-1)&right(list,dim(list)-n)

But Darkerline's is still cooler. Smile


Last edited by Guest on 05 Jul 2010 08:25:38 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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 

Advertisement