Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Beginner who needs some help troubleshooting my c# code  (Read 4953 times)

0 Members and 1 Guest are viewing this topic.

scoob

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    Beginner who needs some help troubleshooting my c# code
    « on: February 24, 2017, 12:54:34 PM »
    I have been working on making a hangman game, and have run into an issue where the error counter only counts one incorrect letter. After that it will not count any other incorrect letters and stops at 1. It is supposed to count up to 7 inccorect letters, where a message telling you that you have lost should appear. (Du har tapt og klarte det ikke denne gangen.) I cannot figure out where my code is incorrect and what elements i need to change in oreder to fix this. Hoping to get some suggestions and help with what I am doing wrong :)

    Thanks in advance! -Jc

    [attachment deleted by admin to conserve space]

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Beginner who needs some help troubleshooting my c# code
    « Reply #1 on: February 24, 2017, 01:58:56 PM »
    You are using the "Feil" variable to try to count  the number of failures, correct?

    But it will always be at most one, because it's declared a local variable and thus won't "survive" for subsequent clicks. You check ifi the guess is wrong,. then increment feil if it is, but feil will always be zero at that point, so the increment will only ever make it 1.

    Move the declaration so that it is a member variable- remove the int Feil=0 inside the button click and move it to above the click event as

    Code: [Select]
    private int feil=0

    Then it will count to 7... And beyond, but I suppose that will be your next problem to tackle :P
    I was trying to dereference Null Pointers before it was cool.

    scoob

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Windows 7
      Re: Beginner who needs some help troubleshooting my c# code
      « Reply #2 on: February 24, 2017, 02:28:06 PM »
      Thanks, that gave me some more insight. But now that I have added that line above the click event for the button none of my labels, textboxes or image references in the code are recognized, for example ( The name txtGjett does not excist in the current context) and the button click event now shows a ( new protected member in sealed class).

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Beginner who needs some help troubleshooting my c# code
      « Reply #3 on: February 24, 2017, 04:51:09 PM »
      Add a semicolon.
      I was trying to dereference Null Pointers before it was cool.