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 / HangMan Game Help - using hands on darkbasic vol 1

Author
Message
LD52
18
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Internet
Posted: 27th Jan 2008 03:44 Edited at: 27th Jan 2008 03:49
I am using hands on darkbasic vol 1 and following what they are saying but i seem to be stuck as something thats in the book i get an error on.

okay so i keep getting an error that command is out of place @ line 105 or the line that has endfunction on it with the return value of letterfound. This is the function :


Now if it helps here is the whole source code that i have:



In the book it says to have endfunction with the return value of letterfound which is supposed to be either a 0 or a 1 as you see with the If statements but i get an error at "endfunction letterfound" which says command is out of place.
I've tried taking away letterfound .. doesn't help.
Any help or ideas are greatly appreciated ...
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 27th Jan 2008 04:04 Edited at: 27th Jan 2008 04:14
you forgot to put
Next c
after the last endif in your checkforletter() function

on my computer got errors when trying to compile your program in the function addtohangedman() where the line and ellipses commands have paranthess basicly to fix ths i took out the paranthases im not sure why you put those there
and in your wordguessed function you mispelled wordguessed
after i fixed those you still got a few more problems when running the code
-you guess one letter and t says you win and then game over right a away

LD52
18
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Internet
Posted: 27th Jan 2008 04:14 Edited at: 27th Jan 2008 04:22
It works ! thanks !
Another thing i get is at this function :


I get an error saying that EXITFUNCTION AND ENDFUNCTION need to return the same data type so what should i do ?
I put a 1 after endfunction to make it the same and it compiled and showed on screen but the game didn't work it just ended the game after the first letter guess.
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 27th Jan 2008 04:17
alrite no problem

LD52
18
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Internet
Posted: 27th Jan 2008 04:27
Quote: "on my computer got errors when trying to compile your program in the function addtohangedman() where the line and ellipses commands have paranthess basicly to fix ths i took out the paranthases im not sure why you put those there
and in your wordguessed function you mispelled wordguessed
after i fixed those you still got a few more problems when running the code
-you guess one letter and t says you win and then game over right a away
"


Lol yea i know. I took away the parentheses and well and corrected the spelling for wordguessed but as you said it ends the game right away with you won and game over. I'm kind of confused with the endfunction and exitfunction returning the same data types ?
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 27th Jan 2008 09:02 Edited at: 27th Jan 2008 09:05
Ok i worked on your code a bit and figured somethings out
i changed a lot of little things that kept comming up and i can't remember right now, so just look at the code and if you have any questions about anything i changed just ask


This code isn't perfect you still have a major bug. I would figure it out but I wouldn't want to have all the fun
Since the code is checking to see if you got a correct letter and when you do it adds 1 to the correctletters variable, you can keep entering the same letter over and over and essentually "win" by just entering it as many times as there are letters in the words. also another thing that is kind of important is you can do the same with a wrong letter by putting the same letter 6 times you loos
-you need to implement some kind of check to see if the letter being entered has already been entered previously. if it has then you tell the user something like "Please choose another letter that one has already been used" and if it hasnt been used then you go on with the check to see if its a correct letter or wrong letter

LD52
18
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Internet
Posted: 28th Jan 2008 00:50
Wow thanks for all your help. Yes it does seem to work way better than my version. I'm going to see what you changed and then i'll attempt fixing the same letter problem. Thanks.
LD52
18
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Internet
Posted: 28th Jan 2008 01:24 Edited at: 28th Jan 2008 01:42
Okay so i fixed the part where if you guessed right and repeat the letter it won't record it as a guess. I'm still working on if you get the guess wrong and repeat the letter, it counts as a guess, on how to stop that.

[Edit] okay so now i figured out how to get that if they get it wrong and repeat it , it won't count as another guess. I think its based on this code :


The only problem is i am confused as to where to put this .
I placed it in function addtohangedman()
and it disables the hang man getting hanged. I tried placing it in checkforletter() didn't work and when i placed it in the main code between repeat and until i got errors about the command until.

Here's the full source code :
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 28th Jan 2008 01:52 Edited at: 28th Jan 2008 02:10
I haven't had time to look at your entire code yet. I'll do it tomorrow. But by just quickly scanning through it seems that your "fix" to not allow to guess the same letter would only guess if that letter was done twice in a row and not if guessed a letter guessed a different letter and then guessed that same letter again. Again, I haven't really looked at it closely so I'm not sure. See if you can find what I mean.

*I was thinking you may be able to use an array to solve your problem with the check. Since your following the book I don't know if you've reached arrays yet.(I haven't read the book.) But you could dimension an array to 26(letters in the alphabet), then every time a guess is entered you turn into ASCII code with the function ASC() then subtract 96 from the answer(since guess$ is converted to lowercase "a" and the ascii code for lower a is 97 you subtract 96 to get 1 so a is correspondent to 1 in the array.) So something like Dim Alphabet(26) then everytime you guess a letter it first checks the array using at the location ASC(guess$)-96 to see if it has a value of either 0 or 1 (0 would mean the letter hasn't been used and 1 means it has) So if you look at that location and a 0 is returned you turn it into a 1 and go on with the drawletter function or wrongletterguessed function if a 1 is returned Print Letter already guessed try another then go back to the checking subroutine you set up.
Once again this is all an idea and I'm not sure if you've covered any of this. But, when I have time if you need I'll help you implement it. If you haven't done so already by then. I'm sure your capable of it but any questions just ask. Let me know if you think you could do it. If you can't I'll work on it when i can
wow getting lengthy I'm all done now so you can start codign aagin.

LD52
18
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Internet
Posted: 28th Jan 2008 02:23
Wow thanks and arrays is the next section so i'll go start reading and
i think i'll be able to code it but i'll have to do it tommorrow. One thing i'm unsure is the 96 and i am wondering if that is only for "a" or if its for all the letters in the alphabet. Like is the a 96 difference between ascii for all capital and lower case letters?
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 28th Jan 2008 03:01 Edited at: 28th Jan 2008 03:07
the 96 is just what i figured out to get the ascii code for that lowercase letters to correspond its position in the alphabet in ascii cod "d" is 100 minus 96 from that and u get 4 which would b its position in the alphabet and it indeed is the forth letter of the alphabet. that works for all lowercase letters, for uppercase letters it would be a 64, but since u use lower$() to convert the guesses to lowercase letters you only need to worry about the 96. you will never use this method again though most likely and is a method i came up with just then when thinking about your code. I like to save myself the headache and just do it the way I know i would be able too.
but if arrays are not until the next section then there has to be a way of checking without using an array I guess. i'm just not sure. Once again i've never dealt with that book or this code before.

*but yeah ok look into arrays and if you want to do it with arrays good. once again tomorrow i'll look into your code and maybe see if you can just change it a little to make it work with out the array, in the mean time you can try using the array as an extra practice. as always please feel free to ask any questions.

LD52
18
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Internet
Posted: 28th Jan 2008 18:24 Edited at: 28th Jan 2008 18:31
Well i figured out arrays abit and added one in. I added a new function which checksprevious letter and should work...




and the full source code:
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 29th Jan 2008 01:39
the array you made with the data system didn't work. the main reason i thought it didn't work is because you didn't have any read command to read the data into the array but i tried adding it and it didn't work that way either i tried a bunch of different ways i could think of and it didn't work so i did it the way i said i was going to and it works for what were trying to achieve, if you guessed a letter it won't let you guess again, except it has one huge flaw, whatever the word that is chosen is it counts those letters as alreay having been guessed. So basically if the program chooses the word london you won't be able to guess any of those letters because the program will return letter already used, so basicall yyou can't win the game ever! i've been trying to iron out but i can't seem to figure it out so i'm posting it to see if maybe someone else's perspective will work to find the problem


LD52
18
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Internet
Posted: 29th Jan 2008 01:48 Edited at: 29th Jan 2008 01:50
Quote: "except it has one huge flaw, whatever the word that is chosen is it counts those letters as alreay having been guessed. "


Are you sure it worked on my computer ?
It did not let me repeat letters.
I could guess letters and I have Won a Game.
I also have lost a game.

To me it seems your version works best.

Thanks for all your help.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 29th Jan 2008 06:03
The letter 'a' has an ASCII code value of 97. So if you deduct 96 from the ASCII value of any lower case character it will equal the position in the alphabet of that character.

For example, 'a' = 97. 97-96=1 and 1 is the position of 'a' in the alphabet.

Likewise, 'b' = 98. 98-96=2 and 2 is the position of the letter 'b' and so on...

If you were using all upper case (which in my opinion looks a lot better for hangman), 'A' has the ASCII code 65 so you would deduct 64 each time instead of 96.

Finally, it amazes me how many programming books you spend hard earned money on have code examples which don't work!

By the time you've sorted out the problems by reading tutorials on here or posting questions, you've learnt the programming skills the code snippet would have taught you - making the book a waste of money!

TDK_Man

sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 29th Jan 2008 09:03
Quote: "
By the time you've sorted out the problems by reading tutorials on here or posting questions, you've learnt the programming skills the code snippet would have taught you - making the book a waste of money!
"


I so totally agree with that! Total pointless wate of money in my opinion.

Happy, always happy!
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 29th Jan 2008 21:24 Edited at: 29th Jan 2008 23:09
Haha good thing i've never spent any money on anything. I got a sample of the hands on book which was the first 4 chapters and it confused me so much and the pictures didn't match what they were talking about. I've learned so much more by just looking through the forum and just reading any posts that seem interesting to me and might be something i'll use later, plus iv've read almost every tutorial on here even all the ones from tdk in the Darkbasic forum sticky. IT's way easier and cheaper to learn that way.
@TDK yeah the thing you said about the ascii code and subtractign from it is what i was trying to explain to LD52.

@LD52 Did it really work for you. I tried it so many times and it didn't work once for me. Oh well I'm glad i posted it up anyways even though i didn't think it worked or else you'd never get a working code. did it work for everyone else too?

*Edit*
Never mind, I just tried it and it worked. I have no idea why it didn't work yesturday. Guess my computer needed a day to take it all in

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Feb 2008 03:10
Actually, I forgot that I covered Hangman as well as Pong in my Programming Logic tutorial 12 here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

It basically covers one way of writing Hangman from a game logic viewpoint rather than a specific tutorial with code.

I don't know if it tackles things any different to what your book says, but it's purpose was to cover the 'theory' of how to write it under the assumption that you already have the programming knowledge.

It doesn't teach you programming in the process...

TDK_Man

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 1st Feb 2008 04:03 Edited at: 1st Feb 2008 04:22
It's quite sad when you get to a point where you've written so many tutorials you forgot which ones you've written.

*Edit*
Would doing the Repeat until Loop from your tutorial for reading the words in the text file work to say increase numberofwords variable and then use that to dimension the array so you never use to many uneeded positions or in some cases not have enough?
It was just a thought I had as I quickly glanced at the tutorial

Another thing is I actually tried putting the alphabet into a whole string like you did.(Before I ever read your tutorial) I had the idea right just didn't know how to implement it. It escaped my mind to use a variable to find the letters position with the mid$() and then delete the letter with the left$() or right$() command. Believe it or not i was actually trying alphabet$ = alphabet$ - guess$ . Haha wow

Login to post a reply

Server time is: 2024-09-27 10:32:54
Your offset time is: 2024-09-27 10:32:54