0 Members and 2 Guests are viewing this topic.
public class MyClass{ public static int foo = 0; static MyClass(){ MyInnerClass.bar = 0; } private class MyInnerClass{ public static int bar; }}
public void DetectNPC(){ [...](Other code in method) Vector2[] PhilCharNPCHitVectors = new Vector2[ArrayLength]; float[] NPCHitXCoord = new float[ArrayLength]; float[] NPCHitYCoord = new float[ArrayLength]; [...]}private void UpdateInput() { OldState = KeyState; KeyState = Keyboard.GetState(); if (KeyState.IsKeyDown(Keys.S) && themap.HitMap[Convert.ToInt32(YCoord) + 1].Substring(Convert.ToInt32(XCoord) * 2, 2) == "..") { YCoord = YCoord + 1; } if (KeyState.IsKeyDown(Keys.W) && themap.HitMap[Convert.ToInt32(YCoord) - 1].Substring(Convert.ToInt32(XCoord) * 2, 2) == "..") { YCoord = YCoord - 1; } if (KeyState.IsKeyDown(Keys.D) && themap.HitMap[Convert.ToInt32(YCoord)].Substring((Convert.ToInt32(XCoord) * 2) + 1, 2) == "..") { XCoord = XCoord + 1; } if (KeyState.IsKeyDown(Keys.A) && themap.HitMap[Convert.ToInt32(YCoord)].Substring((Convert.ToInt32(XCoord) * 2) - 1, 2) == "..") { XCoord = XCoord - 1; } NextMap();}
The problem here is that the arrays are out of scope. That is, they are only defined within DetectNPC(). When you leave DetectNPC() via return, those arrays are cleared off the stack. You should either make them global variables, or members of a class that contains both methods.