0

This is my problem

 private void P1STRtextbox_TextChanged(object sender, EventArgs e)
    {

        if (Convert.ToInt32(P1STRtextbox.Text) > Convert.ToInt32(P1RemainingStatPointsLabel.Text))
        {
            MessageBox.Show("You have enter a number larger than your remaining stat points!");
        }           
        else
        {
            P1RemainingStatPointsLabel.Text = (PlayerOne[P1ClassNumber].TotalStatPoints - Convert.ToInt32(P1STRtextbox.Text)).ToString();
        }
    }
    private void P1DEXtextbox_TextChanged(object sender, EventArgs e)
    {
        if (Convert.ToInt32(P1DEXtextbox.Text) > Convert.ToInt32(P1RemainingStatPointsLabel.Text))
        {
            MessageBox.Show("You have enter a number larger than your remaining stat points!");
        }
        else
        {
            P1RemainingStatPointsLabel.Text = (PlayerOne[P1ClassNumber].TotalStatPoints - Convert.ToInt32(P1DEXtextbox.Text)).ToString();
        }
    }

So basicly the event is triggered when the text in the box is changed. When I input a number into the strength text box at first, it does the deductions properly, but when I go to the Dexterity box and try to edit the value, it does not do the deduction properly. As you can see in the picture(remaining stat points) that 3000-(250+750) != 2250; Can someone please give me some logical advice? Thank you for your time and effort in advance!

2 Answers 2

2

How about changing you P1DEXtextbox_TextChanged else statement to use the below?

P1RemainingStatPointsLabel.Text = (PlayerOne[P1ClassNumber].TotalStatPoints - (Convert.ToInt32(P1STRtextbox.Text) + Convert.ToInt32(P1DEXtextbox.Text))).ToString();
Sign up to request clarification or add additional context in comments.

Comments

2

You are never adding the strength and dexterity values. You need to take both fields into account when changing the remaining stats value:

int strength = Convert.ToInt32(P1STRtextbox.Text);
int dexterity = Convert.ToInt32(P1DEXtextbox.Text);
P1RemainingStatPointsLabel.Text = (PlayerOne[P1ClassNumber].TotalStatPoints - (strength + dexterity)).ToString();

You also have to make sure that you handle possible errors when converting text to an integer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.