none
Help using imported .txt file values to draw a map RRS feed

  • Question

  • hello,

    I am making a simple 2d maze game
    I want to create the map for this game using a .txt file , for example, a 5x5 grid would look like this in the .txt file:

    11111
    10001
    10001
    10001
    11111

    where 1 would be a wall and 0 would be empty space. Using .readline i can get a line, e.g 10001.  Does anyone know how i could seperate these numbers, so that sb could read the first value 1, second value 0, and so on. I want to do this so that my program would know to draw a wall in the first square of the gride, nothing in the second, etc.

    perhaps a better way of phrasing this would be how can i divide the text into columns?

    I tried to use arrays for this but the way i was using them meant it would get a bit silly with a larger map size

    thanks for any help
    Thursday, July 9, 2009 9:23 PM

Answers

  • You can convert your input number into an an array of values (0 or 1)

    input = 10001

    For i = 1 To Text.GetLength(input)
      chars[i] = Text.GetSubText(input,i,1)
    EndFor

    For i = 1 To Array.GetItemCount(chars)
      TextWindow.WriteLine(chars[i])
    EndFor
    • Marked as answer by badgerwatch Thursday, July 9, 2009 9:47 PM
    Thursday, July 9, 2009 9:43 PM
    Moderator

All replies

  • You can convert your input number into an an array of values (0 or 1)

    input = 10001

    For i = 1 To Text.GetLength(input)
      chars[i] = Text.GetSubText(input,i,1)
    EndFor

    For i = 1 To Array.GetItemCount(chars)
      TextWindow.WriteLine(chars[i])
    EndFor
    • Marked as answer by badgerwatch Thursday, July 9, 2009 9:47 PM
    Thursday, July 9, 2009 9:43 PM
    Moderator
  • would you believe I hadnt considered the Text options? i guess i'm newer to this than i thought!

    thats perfect, thanks
    Thursday, July 9, 2009 9:50 PM