none
Multiple Dimension Array RRS feed

  • Question

  • How do you set up a Multiple Dimension Array?

    The Small Basic Tutorials that I down loaded are of no help.

    The just show how to analyze a Multiple Array, not how create one.

     

    This is the example of a multiple array that I am trying to create for role playing game.

    Player["Name"]["Race"][Class][Armor][Strength][Magic]

     

    Wednesday, November 2, 2011 7:30 PM

Answers

  • Try this:

     

    sampleText = "sample Text"
    
    sampleArray[1] = "hello"
    sampleArray[2] = "goodbye"
    sampleArray[3] = "how are You?"
    sampleArray["a string can also be an identifier"] = "value"
    sampleArray["Small Basic is the best"] = "true"
    
    sampleMultidimensionalArray["dog"]["numberOfLegs"] = "4 (sometimes 3)"
    sampleMultidimensionalArray["dog"]["isStupid"] = "true"
    sampleMultidimensionalArray["cat"]["numberOfLegs"] = "4"
    sampleMultidimensionalArray["cat"]["isStupid"] = "false"
    


     


    Thursday, November 3, 2011 5:52 PM
  • Multi-dimensional arrays are just like single-dimensional arrays, just with more dimensions. Most arrays used in Small Basic are single dimensions, like this:

    array[dimension1]="value"

    But to make multi-dimensional arrays you just add more dimensions between brackets []:

    array[dimension1][dimension2]="value"

    array2[dimension1][dimension2][dimension3]="value"

    Most times multi-dimensional arrays are used for X, Y, and Z coordinates, and holding the location of an object. Like in a chess game I wrote, I used an array for setting and getting which piece is in what square. In 3D chess, I wrote:

    grid[x][y][z]="Pawn" 'Or just any other piece. In the actual 3d chess game I would do "w1": white:Pawn

     

    Hope you understand better now.


    ~~AirWaves!!~~
    Sunday, November 6, 2011 3:57 AM

All replies

  • Try this:

     

    sampleText = "sample Text"
    
    sampleArray[1] = "hello"
    sampleArray[2] = "goodbye"
    sampleArray[3] = "how are You?"
    sampleArray["a string can also be an identifier"] = "value"
    sampleArray["Small Basic is the best"] = "true"
    
    sampleMultidimensionalArray["dog"]["numberOfLegs"] = "4 (sometimes 3)"
    sampleMultidimensionalArray["dog"]["isStupid"] = "true"
    sampleMultidimensionalArray["cat"]["numberOfLegs"] = "4"
    sampleMultidimensionalArray["cat"]["isStupid"] = "false"
    


     


    Thursday, November 3, 2011 5:52 PM
  • Multi-dimensional arrays are just like single-dimensional arrays, just with more dimensions. Most arrays used in Small Basic are single dimensions, like this:

    array[dimension1]="value"

    But to make multi-dimensional arrays you just add more dimensions between brackets []:

    array[dimension1][dimension2]="value"

    array2[dimension1][dimension2][dimension3]="value"

    Most times multi-dimensional arrays are used for X, Y, and Z coordinates, and holding the location of an object. Like in a chess game I wrote, I used an array for setting and getting which piece is in what square. In 3D chess, I wrote:

    grid[x][y][z]="Pawn" 'Or just any other piece. In the actual 3d chess game I would do "w1": white:Pawn

     

    Hope you understand better now.


    ~~AirWaves!!~~
    Sunday, November 6, 2011 3:57 AM