Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Setting a variable value from an array.

Setting a variable value from an array.

Scheduled Pinned Locked Moved C#
csharpdata-structures
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jblouir
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • J jblouir

      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

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      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."); }

      my articles

      J 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        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."); }

        my articles

        J Offline
        J Offline
        jblouir
        wrote on last edited by
        #3

        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

        H 1 Reply Last reply
        0
        • J jblouir

          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

          H Offline
          H Offline
          Hesham Yassin
          wrote on last edited by
          #4

          may you try to cast the value that way: if ((int)arrWall[x,y] == 0) { etc... } i think it should work!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups