Setting a variable value from an array.
-
I am currently writing a text adventure in c#. What I have is a 3 by 3 array with 0's and 1's in a specific order. 010 111 010 Basically anywhere theres a 1, thats a valid location for the person to move to. What I need is a way to pull the value out of an array position say array[1,1] This isnt all the code but you get the picture. int intWall = 0; intWall = arrWall[x,y]; if (intWall == 0) { Console.WriteLine("You can't move that way."); } // I need some way of putting the value of the x,y spot in the array to the variable
-
I am currently writing a text adventure in c#. What I have is a 3 by 3 array with 0's and 1's in a specific order. 010 111 010 Basically anywhere theres a 1, thats a valid location for the person to move to. What I need is a way to pull the value out of an array position say array[1,1] This isnt all the code but you get the picture. int intWall = 0; intWall = arrWall[x,y]; if (intWall == 0) { Console.WriteLine("You can't move that way."); } // I need some way of putting the value of the x,y spot in the array to the variable
Do you need this:
arrWall[1,0]=0; arrWall[1,1]=1;
?jblouir wrote:
int intWall = 0; intWall = arrWall[x,y]; if (intWall == 0) { Console.WriteLine("You can't move that way."); }
You can write just this:
if (arrWall[x,y] == 0) { Console.WriteLine("You can't move that way."); }
-
Do you need this:
arrWall[1,0]=0; arrWall[1,1]=1;
?jblouir wrote:
int intWall = 0; intWall = arrWall[x,y]; if (intWall == 0) { Console.WriteLine("You can't move that way."); }
You can write just this:
if (arrWall[x,y] == 0) { Console.WriteLine("You can't move that way."); }
-
Odd I thought I tried that, thanks =). I am pretty sure I tried to check the value using... if (arrWall[x,y] == 0) { etc.. } and it came back with something like cant perform on Its working now though thanks for the help! =D
may you try to cast the value that way: if ((int)arrWall[x,y] == 0) { etc... } i think it should work!