Databases for Robots

There is need of feature that store data in an array, so that one particular item of the data can be picked out simply by referring to its index (the number of its position) in the array. This chapter discusses how to implement look-up tables in NXT-G. The makearray program serves such purposes. The main element is a switch block that holds the array data. This program will hold the names of five weekdays. When the switch block is first put on the screen, it is in its default state. It has only two branches, numbered 1 and 2, and these are allocated input condition values 0 and 1. It takes each block in turn by selecting the tab on the switch block, place one variable block on each branch. At this stage, one can turn the program (the index block plus the switch block) into any block and run it. This program operates on the principle of having a single variable, index , which can be given any one of a number of values, depending on the values inserted when the switch block was constructed. A number is loaded into an index and, when the block is called, the corresponding value of datum is returned.