Variables in buttons in C# -
i have school project , i'm making game. here's code:
public partial class room2 : form { public room2() { initializecomponent(); random rand1 = new random(); int32 t =6 ; int32 fight = rand1.next(1, 11); int32 j = 10; label4.text = convert.tostring(10); if (fight <= t) { label3.text = convert.tostring(j); } else { txtdialogbox.text = ("no fight in room"); } } private void attack_click(object sender, eventargs e) { random rand2 = new random(); int32 j = 10; int32 attack = rand2.next(1, 4); int64 y = 1; int64 t = 10; //opponents hp bar goes down 1 j --; label3.text = convert.tostring(j); // chance hp bar go down if (attack >= y) { label4.text = convert.tostring(t); t--; } } }
when put ints @ top (like told ) errors ("does not exist in current context") , found way me fix put in button.
you have take off few variable , declare them globally used methods.
that should this
public partial class form1 : form { int32 t = 6; int32 j = 10; public form1() { initializecomponent(); random rand1 = new random(); int32 fight = rand1.next(1, 11); label4.text = convert.tostring(j); if (fight <= t) label3.text = convert.tostring(j); else txtdialogbox.text = ("no fight in room"); } private void attack_click(object sender, eventargs e) { random rand2 = new random(); int32 attack = rand2.next(1, 4); int64 y = 1; //opponents hp bar goes down 1 j--; label3.text = convert.tostring(j); // chance hp bar go down if (attack >= y) { label4.text = convert.tostring(t); t--; } } }
Comments
Post a Comment