Monday, 15 March 2010

c# - The name TimeLeft does not exist in the current context -



c# - The name TimeLeft does not exist in the current context -

this question has been closed.

this different other questions i've seen related this. have 2 forms in mario game, right? set public integer in 1 of them, gamegui.cs. in timerstatus.cs want display variable says message "the name timeleft not exist in current context."

here's of code.

public partial class timerstatus : form { int timersecondsleft = timeleft * 0.6; public timerstatus() { initializecomponent(); } private void timerstatus_load(object sender, eventargs e) { label1.text = "you have " + timeleft + " seconds remaining."; } }

this code timeleft stored.

public partial class gamegui : form { public int timeleft = 400; bool right, left; bool isfacingleft = false; bool jump; int g = 16; int force; int walkspeed = 1; int score = 0; int lives = 3;

bool iswalkframeone = false; byte animtime = 4; public gamegui() { initializecomponent(); }

remember they're in 2 different forms.

thanks can help. :)

problem : trying access timeleft if declared in same class. inorder access variables declared in outside class need class instance fellow member or if declared static can access using classname.

note: need declare variables static belong whole class.

solution: in programme timeleft variable seems tobe classlevel variable can declare timeleft variable static in gamegui class file. can access other classes using classname.

try this:

public partial class gamegui : form { public static int timeleft = 400; bool right, left; /*remaining code here*/ }

access using classname gamegui

public partial class timerstatus : form { int timersecondsleft = gamegui.timeleft * 0.6; public timerstatus() { initializecomponent(); } private void timerstatus_load(object sender, eventargs e) { label1.text = "you have " + gamegui.timeleft + " seconds remaining."; } }

c# integer public

No comments:

Post a Comment