EDIT: Wrote this as reaction to your first message, did not see the other 2. You are correct, thinBasic arrays are 1 based by default. We may consider adding different base in the future, but there is no ETA.
Merry Christmas, Benjamin!,
the note about subscripts is related to so called arrays.
Arrays are great way to pack multiple items of the same type together, while allowing better flexibility than normal variables.
One dimensional array
Should you want to store names of your 3 friends and then print each, you can do this:
USES "Console"
' Initialize array with values
DIM friends(3) AS STRING = "Alex", "Bill", "Cecile"
' Change your mind about second friend:
friends(2) = "Benjamin" ' Changes "Bill" to "Benjamin"
DIM i AS LONG
FOR i = 1 to countOf(friends)
PrintL friends(i)
NEXT
WAITKEY
Anytime you want to increase number of friends you just increase the number to new number (for example 5) and the code will still work.
If you would have just variables friend1, friend2, friend3 - it would be much harder to maintain the code.
Please note the subscript is always 1 based at the moment. So specifying 3 as subscript means having friends(1), friends(2) and friends(3) created for you.
CountOf is a great function to return number of items in 1 dimensional array.
Two and more dimensional arrays
You are not restricted to just 1 dimensional arrays, but you can use 2 dimensional, 3 dimensional.
Here is again a little example:
USES "Console"
' Initialize Tic-Tac-Toe game with empty cells
DIM ticTacToe(5, 4) AS STRING = " ", " ", " ", " ", " ",
" ", " ", " ", " ", " ",
" ", " ", " ", " ", " ",
" ", " ", " ", " ", " "
' Write initial player 1 move
ticTacToe(2, 3) = "x"
' Write initial player 2 move
ticTacToe(3, 3) = "o"
DIM column, row AS LONG
Dim singleCell aS STRING
' Iterate through all cells in the array to draw Tic-Tac-Toe board
FOR row = 1 to CountOf(ticTacToe, 2) ' Count of items in second array dimension
FOR column = 1 to CountOf(ticTacToe, 1) ' Count of items in first array dimension
' Draw single cell
singleCell = " " + ticTacToe(column, row) + " |"
Print singleCell
next
' Draw row separator
printl
printl repeat$(CountOf(ticTacToe, 1) * len(singleCell), "-")
next
WAITKEY
Hope this helps to get some initial inspiration. One more tip - have a look in the help file at ARRAY statements. They can help you with some common tasks such as sorting, shuffling and more.
Petr
Bookmarks