Shop OBEX P1 Docs P2 Docs Learn Events
Multi-dimensional arrays?? — Parallax Forums

Multi-dimensional arrays??

wired_alwired_al Posts: 2
edited 2010-08-24 13:50 in BASIC Stamp
I am attempting to give my boe-bot a memory of the floor and where objects are so I can send him a location via a wireless transponder and have him navigate there without running into a wall and then on my screen it will draw a map of the memory and update whenever the bot finds a wall or other object.

In order to accomplish this I need to know if the latest version of P-Basic supports multi-dimensional arrays. I only need a two-dimensional array to map out the floor. From what I have read, it does not, which is sad because most programming languages do. Is this a feature that is hidden? Or will it be released soon? I have a competition coming up in October so it would be nice to know this soon.

Thanks
wired_al

Comments

  • LeonLeon Posts: 7,620
    edited 2010-08-22 21:13
    You can simulate them. Suppose you need a 3x4 array: create a single-dimensional array with 12 entries and keep tabs of the rows and columns with a couple of variables. That sort of thing is done all the time in assembler, and was also necessary with some of the early programming languages like BCPL.
  • wired_alwired_al Posts: 2
    edited 2010-08-22 21:41
    I was just coming back to post that I had remembered that from an old game I programmed hehe. For anyone who might be experiencing the same need here is the code for what I did
    MapWidth CON 10
    MapHeight CON 10
    
    Map VAR Bit (MapWidth * MapHeight)
    TileX VAR Word
    TileY VAR Word
    CurrentTileVal VAR Bit
    
    TileX = 5
    TileY = 4
    
    CurrentTileVal = (TileY * MapWidth + TileX)
    

    Thanks for your help....
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-22 21:41
    Leon is partly right. If you want to have multi-dimensional arrays, you have to simulate them using a single dimension. What he didn't say is that there's very limited variable storage on a Stamp, exactly 26 bytes. You can create a bit array, but that's limited to 26 x 8 bits = 208 bits and that leaves nothing for loop counters or temporary variables, etc.

    You can use EEPROM to store a map of an area using READ, WRITE, and DATA statements. You have to be very careful about writing to EEPROM though. A given location in EEPROM can only be written about 100,000 times. That may seem like a lot, but it's very easy to exceed that in a few hours if there's a program bug or if a program is written badly. Usually when people create a navigation map they store it in the EEPROM.
  • skylightskylight Posts: 1,915
    edited 2010-08-24 13:26
    just out of interest Wired_AL was the game you programmed a version of minesweeper? I used the technique to program that game on a Psion 3
  • ercoerco Posts: 20,256
    edited 2010-08-24 13:50
    Storing an accurate environment map is quite challenging. Getting a BoeBot to accurately navigate from A to B "knowing" where it is will be orders of magnitude harder. That road is fraught with peril. What's your general navigation plan? Dead reckoning, wheel encoders, bump switches, Sharp optical sensors, Ping))) .... Doing it properly and well with a simple robot could be the stuff of a Master's thesis.

    But good luck, and please keep asking questions and keep us updated!
Sign In or Register to comment.