Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / asc command....i guess? [dbpro]

Author
Message
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 24th Dec 2005 07:43
What I want is a '*' to be the blanks in my hangman game and when the correct letter is pressed them the '*' disappears and the correct letter is printed in its place. I can't seem to figure out how though. I was thinking of somehow using the asc command and make a loop checking the string for all letters with the same ASCII value and print them, but the asc command only returns the first string's value so then I thought that I will have to somehow store each letter of each string in it's own variable; perhaps an array. Thank you!!!

so far, this is what i have:


this was just a test, and it helped me to come to the realization I stated above. Any help would be greatly appreciated.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 24th Dec 2005 08:21 Edited at: 24th Dec 2005 08:22
A quick way of doing it, would be making a "****..." string before the loop(same length ofcourse). And when the character is reveiled, replace the * with the correct character.

if FoundWord = state$(n) then win = 1
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Dec 2005 11:28
Quote: "ASCII value and print them"


Sven B is right. "blank$" needs to be exactly the same length as your word... don't add spaces after each *. It's much easier to check and modify if their both the same length.

You can use a for/next loop and check each character in "rndword$" using the "mid$" command... when it sees the character your looking for make a new "blank$" with the left side of "blank$" + the "mid$" character in "rndword$" + the right side of "blank$".

In the past you didn't want code... just somebody to point you in the right direction... but if you want the code solution just ask.


Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 25th Dec 2005 22:27
Quote: "In the past you didn't want code... just somebody to point you in the right direction... but if you want the code solution just ask."


that is still the case, i like to learn on my own, but i need direction. i wasn't sure about the asc because i have never used, or seen it been used, before. thanks for your help. i will try it out now.
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 26th Dec 2005 02:18 Edited at: 26th Dec 2005 02:23
first, in my code for guessing the letters of the state, my code looked like this but you could only guess the letters in order. I know why, it is because of the letter value in the mid$ function.



So then, I tried to take your advice about left$, mid$, and right$ but apply it to guessing the letter instead of the blanks. but it always prints "INCORRECT". I am not sure why.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Dec 2005 03:56 Edited at: 26th Dec 2005 03:57
Quote: "that is still the case, i like to learn on my own, but i need direction. i wasn't sure about the asc because i have never used, or seen it been used, before. thanks for your help. i will try it out now. "


I know how you feel... i'm the same way. "asc" is very useful indeed... like when you want to write a string to a memblock, use a bitmap font, or make an encryption routine. But in this case the program asks for a string and what you want it to check is a string so theres no need to use "asc" because of "mid$".

It's better to use "entry$()" rather than "input"... input requires the user to press enter and they can type in more letters than just one. You can set it up to take only one letter from "entry$()" then "clear entry buffer" so that letter is removed from the list. Also "entry$()" needs to be outside of the for/next loop that checks for the letter.

After the letter is taken from "entry$()" (or not... which means the for/next loop needs to be inside an if/then that checks if the string taken from "entry$()" is more than nothing) then do a for/next loop that goes from 1 to the length of the string... to look for the letter you got from "entry$()". If it finds the single letter then do the "blank$" = "left$(blank$)" + mid$(word$)" + "right$(blank$)" to replace the * with the letter from "word$" into "blank$".

The check for the whole word should be after the for/next loop check for the individual letters.


Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 26th Dec 2005 04:54
Quote: "do a for/next loop that goes from 1 to the length of the string... to look for the letter you got from "entry$()". "


that is the part that I am having trouble with. my question changed slightly from the first post. my query is not with the blanks anymore, now it is with checking to see if the letter the user guesses is in the hidden word, hence me stating earlier
Quote: "So then, I tried to take your advice about left$, mid$, and right$ but apply it to guessing the letter instead of the blanks. but it always prints "INCORRECT". I am not sure why."
so my question now is, how can I make it so that i can input the letters that make up the hidden word out of chronological order?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Dec 2005 05:44
It's hard to tell you without code... so i'll use code you've made.



In your first code snip you started out right. You can do the above or just a straight "n=1 to len(rndword$)". In between the for/next you need the if/then that checks if the string taken from "entry$()" is the same as the "mid$" of "rndword$". Even if it sees a letter it won't stop until it goes though all the chracters in "rndword$".

Just remember... any input needs to be changed to highercase (or lowercase) and "rndword$" needs to be the same case you use for the input. "A" and "a" aren't the same.


Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 26th Dec 2005 08:18
actual code would be good this time because I can't find any info anywhere explaining the entry$(). how do you place restrictions on the user's input, i.e. number of characters, and then clear entry bufer?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Dec 2005 10:18
"entry$()" is located in the Input Commands area of the help files (right under "keystate()"). The Index area of the help files list all the commands alphabetically.

"entry$()" holds all the characters typed without instant output to the screen (like with "input")... when you say "a$=entry$()" it equals all the keys that have been typed (since the program started). Using "clear entry buffer" wipes out all the information so "entry$()" only holds the latest keys pressed. If you wipe it out right after getting the latest keypress it'll only hold 1 character.

Before "entry$()" existed we used "inkey$()" which only takes one character without the need to clear the buffer. Actually you might even like that better than "entry$()".

Rem off the second "clear entry buffer" and you'll see why it's needed for your program.



Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 27th Dec 2005 19:11 Edited at: 27th Dec 2005 19:55
i'm still tryin, the entry$() is not workin right. so i will just stick with the input command. I was looking at a hangman program in the code base, and then many others in the code base and found that they don't really do much documentation of what they are doing in the code so it's really hard to understand for a newbie like moi. here's what i have so far, it's still a bit buggy; the part where the new blank$ is printed. :

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 27th Dec 2005 21:24
You're so close! There's just one mistake in "right$". I know you don't want me to tell you outright so I made code to help you test out the routine (separate from your program).

Remember "right$" takes characters from right to left. You just need to change it (in the following code snip) to take 4 letters rather than 3... but do it in such a way that it uses all available information about that string so it can be used for more than just "virginia".

This is what your routine is doing:



Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 27th Dec 2005 22:50
aww man! thanks for sticking it out with me. you're the best.

Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 27th Dec 2005 23:04
now, all i got left to do is make it so there are 10 possible mistakes and if you make ten then gameover and the word is shown, and add more states
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Dec 2005 03:46
Quote: "aww man! thanks for sticking it out with me. you're the best."


Np. I knew you'd get it.


Login to post a reply

Server time is: 2024-11-12 05:31:58
Your offset time is: 2024-11-12 05:31:58