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
Author Message
Bhaliar


Member


Joined: 16 Nov 2009
Posts: 221

Posted: 22 Nov 2009 08:28:35 pm    Post subject:

Okay, so I am trying to make a hangman game, and started with trying to make something that lets the user type in a letter. The word is then searched, and the letter is put at a spot in the screen.

I ran into a problem though. When I execute my program, no matter what letter I type, A comes out. Below is the program. Can anyone tell me what I did wrong and how I can fix it?

:0->B
:Lbl 1
:" "->Str2 // One space.
:0->K
:While K=0
:getkey->K
:End
:K-(K-1)->K
:sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",K,1)->Str2
:Output(1,B+1,Str2
:Goto 1

My idea was, when you hit the letter, It is stored to K. K is then subtracted by one less then itself, so if K was 41, then it would be 41-(41-1)->K. It then uses sub to retrieve the right letter nd output the letter, But whenever I use it, it outputs a for every letter, and then wont put out anymore letters.
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 22 Nov 2009 08:48:04 pm    Post subject:

Take a closer look at the expression K-(K-1). What does that simplify to?


You have the right idea! Perhaps you could get a few ideas from this routine.


Last edited by Guest on 01 Jul 2010 10:13:41 am; edited 1 time in total
Back to top
GloryMXE7
Puzzleman 3000


Active Member


Joined: 02 Nov 2008
Posts: 604

Posted: 22 Nov 2009 08:48:07 pm    Post subject:

your math is wrong
k-(k-1) will always output 1
and even if you math was right it still wouldn't work
because the getkey codes dont go 1,2,3,4,5...,n

darn too late


Last edited by Guest on 22 Nov 2009 08:48:58 pm; edited 1 time in total
Back to top
Bhaliar


Member


Joined: 16 Nov 2009
Posts: 221

Posted: 22 Nov 2009 09:35:05 pm    Post subject:

Ed H wrote:
Take a closer look at the expression K-(K-1). What does that simplify to?


You have the right idea! Perhaps you could get a few ideas from this routine.


Ahhhh. I see it now. Wow stupid mistake. Thanks. And I know the ti|bd version. I just want a simplified version that does letter by letter, and on the homescreen.

How should I change The K-(K-1)? hmmm.


Last edited by Guest on 01 Jul 2010 10:13:58 am; edited 1 time in total
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 22 Nov 2009 09:46:37 pm    Post subject:

One thing you should notice and take advantage of is that the getkey pattern for letters follows a fairly regular pattern. The only problem is, the line with A, B, and C only has 3 letters, while the rest of the lines have 5 letters. The clever thing to do is to use dummy characters, like sub("ABC**DEFGHIJKLMNOPQR....

Then, the only thing that remains is to somehow get the getkey values 41, 42, 43, 44, 45, 51, 52, 53, 54, 55, 61, etc. to increase linearly. Some clever int( and fPart(ing should do the trick.

Spoiler: [whiteout]K-15-5int(.1K[/whiteout] works with my string.


Last edited by Guest on 12 Jul 2010 01:03:00 am; edited 1 time in total
Back to top
GloryMXE7
Puzzleman 3000


Active Member


Joined: 02 Nov 2008
Posts: 604

Posted: 22 Nov 2009 09:47:34 pm    Post subject:

some alternatives
input "Guess:",Str1
or
1->x
"ABCDEFGHIJKLMNOPQRSTUVWXYZ->Str1
DelVar kwhile k≠105
getkey->k
x+(k=26)-(k=24
if (26-ans)(ans-1)<0
27-ans-Not(ans
ans->x
output (1,1,sub(Str1,ans,1
end
sub(Str1,x,1->Str2


Last edited by Guest on 22 Nov 2009 09:50:51 pm; edited 1 time in total
Back to top
Bhaliar


Member


Joined: 16 Nov 2009
Posts: 221

Posted: 22 Nov 2009 10:04:06 pm    Post subject:

Ed H wrote:
One thing you should notice and take advantage of is that the getkey pattern for letters follows a fairly regular pattern. The only problem is, the line with A, B, and C only has 3 letters, while the rest of the lines have 5 letters. The clever thing to do is to use dummy characters, like sub("ABC**DEFGHIJKLMNOPQR....

Then, the only thing that remains is to somehow get the getkey values 41, 42, 43, 44, 45, 51, 52, 53, 54, 55, 61, etc. to increase linearly. Some clever int( and fPart(ing should do the trick.

Spoiler: [whiteout]K-15-5int(.1K[/whiteout] works with my string.


Well if you subtract one less then k from itself it should increase linearly, because k wont equal non letter keys after the 30s.
I tried to do

:K-1->C
:K-C->K

but it didn't work.


Last edited by Guest on 12 Jul 2010 01:11:52 am; edited 1 time in total
Back to top
GloryMXE7
Puzzleman 3000


Active Member


Joined: 02 Nov 2008
Posts: 604

Posted: 22 Nov 2009 10:23:06 pm    Post subject:

it didnt work because you did k-(k-1 again but coded it different
k-(K-1)=k-k+1=1


Last edited by Guest on 22 Nov 2009 10:26:49 pm; edited 1 time in total
Back to top
Bhaliar


Member


Joined: 16 Nov 2009
Posts: 221

Posted: 22 Nov 2009 11:49:23 pm    Post subject:

GloryMXE7 wrote:
it didnt work because you did k-(k-1 again but coded it different
k-(K-1)=k-k+1=1


Oh. Wow another stupid mistake on a stupid mistake. XD

hmmmm.

I might have an idea.


Last edited by Guest on 22 Nov 2009 11:55:23 pm; edited 1 time in total
Back to top
Bhaliar


Member


Joined: 16 Nov 2009
Posts: 221

Posted: 23 Nov 2009 12:13:01 am    Post subject:

In theory could I use instring for String of "31,32,33,41,42 etc?
Then the number it returns is stored to K and then k is used for sub(abcdef etc.
Back to top
Bhaliar


Member


Joined: 16 Nov 2009
Posts: 221

Posted: 23 Nov 2009 12:28:36 am    Post subject:

ahah got it. Use instring of string "414243515253545561626364657172737475768182838485919293" stored to C. Then C+ (B+1) The B will be -1 first and then progress.
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 23 Nov 2009 01:17:41 am    Post subject:

Now that's what programming is all about.
Back to top
kinkoa


Member


Joined: 28 Jul 2009
Posts: 103

Posted: 23 Nov 2009 09:51:19 am    Post subject:

hangman... used to play that on a dry erase board but never on a calculator
Back to top
Bhaliar


Member


Joined: 16 Nov 2009
Posts: 221

Posted: 23 Nov 2009 12:21:28 pm    Post subject:

Ugh. ran into a diffrent problem. I can't get instring to serch for the numbner related to a variable. Razz trying someother things, but not really working. Took a break for a maze game.
Back to top
kinkoa


Member


Joined: 28 Jul 2009
Posts: 103

Posted: 23 Nov 2009 03:02:02 pm    Post subject:

i feel stupid now i actually looked at the keys to see what was on the lines 4-9 for your instring and after trying to figure it out for about three minutes i realized it was the letter keys
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 23 Nov 2009 03:47:33 pm    Post subject:

You had the right idea earlier. Here's one way to go from a getKey value to a letter:


Code:
:While 1
:getKey→K
:If K>30 and K<94
:Disp sub("ABC  DEFGHIJKLMNOPQRSTUVWXYZ",K-20-5int(.1K),1
:End


The line that does all the work is the 4th line.


Last edited by Guest on 23 Nov 2009 03:47:48 pm; edited 1 time in total
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 23 Nov 2009 04:10:18 pm    Post subject:

Also, a great way to check if a word is in a String:

Inputs:
Str1 contains everything seperated with spaces. Ex of Str1: " HI THIS COULD BE USEFULL IN YOUR GAME RANDOM WORDS MAKE SURE OF THE SPACE "
Str2 contains the word you want to know if it's in the string. Ex of Str2: "RANDOM"

not(not(inString(Str1," "+Str2+" "

Output:
1: It's in there
2: It's not in there.


Last edited by Guest on 01 Jul 2010 10:16:13 am; edited 1 time in total
Back to top
Bhaliar


Member


Joined: 16 Nov 2009
Posts: 221

Posted: 02 Dec 2009 05:32:23 pm    Post subject:

Well I was trying not to use the exact codes, but im gonna try using Ans-15-5int(.1K) Etc.

I already knew how I was gonna do word selection. String 4 and 5 will contain a list of five lettered words and four lettered words. I will Take one out and store it to string 3. Then because the letter is in string 2 use instring to get the number and store it to a variable. This number controls where on the screen the letter is output.
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 UTC - 5 Hours

 

Advertisement