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 issues

Author
Message
Odoyle87
12
Years of Service
User Offline
Joined: 30th Jan 2012
Location:
Posted: 30th Jan 2012 23:38
Hey guys. I'm having two different issues. The first is that when correct answers are made, the hangman persists to be drawn. The second issue is that I need the program to be able to be replayed until "qq" is entered. I've very new and hope that you all can help. Thanks a ton before you start!

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 31st Jan 2012 18:42 Edited at: 31st Jan 2012 19:00
I'll look over your code in a sec, but at a glance I see one thing, you really should use INC and DEC instead of



do this



inc means increment/increase, don't know which.

dec means decrement/decrease.

Oh yeah, and I don't want to overload you on information, but there is a way to do input better.

Instead of:



do this:



EDIT: Your second problem is easy:



Just put start:
at the beggining of you program. (Line 1)

and I think you first problem is just that your saying if its not found, increase error, but then the next if says if its not found and error = 2, but you just increased error, so it keeps on going.

What you need to do is increase error when they get an answer wrong, (Pretty much not in the same place as the if statements) then the if will only go once. (Until another answer is wrong)

-------------------------------------------------------------
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 31st Jan 2012 20:59
Quote: "you really should use INC and DEC"

Using inc or dec over a = a + 1 or a = a - 1 is really just a personal preference since they do exactly the same thing. Odoyle, use which ever you like best, it doesn't change the outcome of your code.

Quote: "Just put start:
at the beggining of you program. (Line 1)"

This could be problematic if he wants to retain data throughout each round. In this case it could work but always be aware of the potential consequences when doing this.

@ Odoyle: I'm having a bit of trouble following your code simply because it's all bunched up and it's very hard to see where an block statement (if, while etc) ends. DBP allows you to have as much 'white space' as you like (in theory) so space out your code and in block statements at an extra 'tab' on each line inside that block statement. An example of what I mean.

Instead of this:


Have this:


In the second code snippet it is much easier to see which 'endif' belongs to which 'if' statement and to see where the print occurs.

Also put a whole line in between block statements as it also helps readability. e.g


Indenting your code makes it much easier for everyone to read and debug. So have a go at indenting your code.

29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 1st Feb 2012 01:39 Edited at: 1st Feb 2012 10:45
Quote: "when correct answers are made, the hangman persists to be drawn"


The reason for this is you weren't setting the variable "found" to 1 (or something other than 0) when the player guessed a letter correctly.

So at the line:

if found = 0 and error = 0

found was always equal to 0 so the program will always draw the stick man no matter what the player does.

I've modified your code to correct this:

Edit: code modified to show correct indenting




You'll also notice that I've indented the code how I would indent it, as Hogey stated this makes the code easier to read. I've also added in a bit of white space (blank lines) for the same reason. You could also do with a bit more commenting.

As for the other stuff you've been criticized for, I agree with Hogey when using inc and dec instead of "variable = variable + 1" it's a matter of preference, although I have a feeling inc and dec are faster (someone correct me if I'm wrong). I also think that using INPUT and PRINT commands are useful for a beginner as I think they're nice and easy to use (just my thought on the topic). I don't think either of these two are particularly criminal.

If I was going to criticize anything, I think your approach is a bit brute force and you're not using the arrays in a particulary clever way. For instance this:



can be rewritten like this:



You might want to look at the SELECT... CASE... ENDCASE... ENDSELECT commands as this might tidy up your nested if statements and you might want to look at either the DATA command or reading from external files for the list of words.

Quote: "... I need the program to be able to be replayed..."


This is all a matter of structure and having loops within loops. It would look something like this (a crude bit of psuedo code so don't try to run this):



You might also want to look at some of the games on the 20 line challenge board, as they might have a replay option (I know mine do) and have expanded easy to read versions.

Hope this helps.
Odoyle87
12
Years of Service
User Offline
Joined: 30th Jan 2012
Location:
Posted: 1st Feb 2012 03:30
Thanks so much for all of the help and constructive criticism! I really appreciate the time and effort and plan to use this as a way to improve my abilities.
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 1st Feb 2012 10:49
Glad you found all the help helpful, it always helps when people thank others for their help.

I just spotted some mistakes with my indenting (does anyone else review their old posts?), which I've now corrected. See my previous post for the modified code.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 2nd Feb 2012 11:27
Sorry guys kinda skimmed through a little... just the code snippets after seeing the wordlists I thought tk myself... DATA... it would be better to use DATA "hello", "world","test", as is done in tge HODBPro book one...

Also

I read the thread title and ... *giggle lol*

Odoyle87
12
Years of Service
User Offline
Joined: 30th Jan 2012
Location:
Posted: 16th Feb 2012 01:33
Sorry to be asking for help again but I've got a serious hidden bug in my game now that is irking me! I've tried to get my program to read outside text which is attached to this post but after playing a few times it gives an error message at "line 78" saying "runtime error 118- array does not exist or array subscript out of bounds."

Any help would be greatly appreciated! I need to have this finished by Friday midnight.

Attachments

Login to view attachments
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 16th Feb 2012 06:14
Your problem is this little piece of code:


It should be:


The reason being that your word list has 9 words. You then create the array wordarray(x-1), x being the number of words in your file. So this currently has 9 cells, 0-8. You then call the first snippet, which returns 0-12. If the number is greater than 8 then it will go "out of bounds". My second snippet should fix this.

Login to post a reply

Server time is: 2024-11-23 22:35:26
Your offset time is: 2024-11-23 22:35:26