locked
Question: How to pull in repetitive data. RRS feed

  • Question

  • Applesoft BASIC had Read/Data commands that would allow assigment of data, from "Data", to a variable via the Read command.

    I can't remember the exact syntax but something like this:

    Read X, [number position of data]
    Data: 1stdata, 2nddata, 3rddata ...etc

    So if the command is "Read X, 2" then X will equal '2nddata'.

    What am I trying to do?
    Come up with a way to call up grid data for the 3D maze program I am working on.
    I need to setup a Sub that will pull the grid data (from somewhere) to know where to draw the walls.
    To make it simple, each X,Y coordinate on the grid is either a wall or not a wall (hallway).

    As the user moves forward or back, pull in the data for the grid coordinates around the new location on the grid.

    As I was typing this, I was thinking that I could use an string array.
    Like
    Array.SetValue("Row",1,"10010")
    So first row of the maze has a wall in the first column, no wall in the next two columns, wall in the 4th column, and no wall in the 5th column

    Anybuddy have any ideas?


    Friday, November 21, 2008 3:53 AM

Answers

  • You can use File to do this:

    Create a file called Data.txt, paste the following in it:

    8
    11111111
    10000001
    10111111
    10000001
    11110111
    10010101
    10000001
    11111111


    and save it as C:\Data.txt
    and this is how you can access the data:

    Path = "C:\" 
     
    Row = 0 
     
    NumberRows = File.ReadLine(Path + "Data.txt", 0)  
     
    For D = 1 To NumberRows  
        Array.SetValue(Row, D, File.ReadLine(Path + "Data.txt", D+1))  
        TextWindow.WriteLine(Array.GetValue(Row, D))  
    EndFor  
     

    • Marked as answer by Path_drc Friday, November 21, 2008 2:31 PM
    Friday, November 21, 2008 4:23 AM

All replies

  • You can use File to do this:

    Create a file called Data.txt, paste the following in it:

    8
    11111111
    10000001
    10111111
    10000001
    11110111
    10010101
    10000001
    11111111


    and save it as C:\Data.txt
    and this is how you can access the data:

    Path = "C:\" 
     
    Row = 0 
     
    NumberRows = File.ReadLine(Path + "Data.txt", 0)  
     
    For D = 1 To NumberRows  
        Array.SetValue(Row, D, File.ReadLine(Path + "Data.txt", D+1))  
        TextWindow.WriteLine(Array.GetValue(Row, D))  
    EndFor  
     

    • Marked as answer by Path_drc Friday, November 21, 2008 2:31 PM
    Friday, November 21, 2008 4:23 AM
  •  Cool idea Rushworks.

    I could write a map editor program to give me a 2D, overhead view of the maze and write the .txt file for me.

    Any idea the character limit for variables?
    255 maybe?

    The only problem I can see with this idea is having to ship the .txt file with the executable and the program recognizing the file path - where ever someone would choose to save them.

    The alternative, I guess, is to just hard key the array into the program (which is what the Read/Data would have been), but I like the text file idea better.
    • Marked as answer by Path_drc Friday, November 21, 2008 2:30 PM
    • Unmarked as answer by Path_drc Friday, November 21, 2008 2:31 PM
    • Unmarked as answer by Path_drc Friday, November 21, 2008 2:31 PM
    • Unmarked as answer by Path_drc Friday, November 21, 2008 2:31 PM
    Friday, November 21, 2008 2:30 PM