### Compatibility Step 6 -- Multi dimensional Arrays

This one was not straight forward because javascript doesn't have a simple syntactic construct to create a multi dimensional arrays. As of today though, QuiteBASIC has just that. For example:

10 DIM A(5,6,4)

declares a 3D array.

The array can then be used in LET commands and in expressions just like you expect it to. For example:

20 LET A(1,2,3) = 64

30 PRINT SQR(A(1,2,3))

will print 8.

This only works with the DIM command. The ARRAY command just declares a 1D array of dynamic size. And this only works with the parenthesis syntax for array indices. So A[1,2,3] is a syntax error.

I also added the TAB(x) function which is typically used in PRINT commands to format the output. For example:

40 PRINT TAB(5); "Hello!"

will print five spaces followed by "Hello!".

## 2 Comments:

1000 cls

1000 print "initialize board"

1010 let m = 49 : rem upper bound of board

1020 dim B(1,m,m)

1030 for x1 = 0 to m

1040 for y1 = 0 to m

1050 let B(0,x1,y1) = 0

1060 let B(1,x1,y1) = 0

1070 next y1

1080 next x1

1090 print "finished initializing board"

1092 print "initializing live cell list"

1093 let c = 0 : rem count of live cells current gen

1094 let c1 = 1 : rem count of live cells next gen

1100 dim X(1,m*m)

1110 dim Y(1,m*m)

1130 for x1 = 0 to m

1140 for y1 = 0 to m

1150 let X(0,x1) = 0

1160 let Y(0,y1) = 0

1170 let X(1,x1) = 0

1180 let Y(1,x1) = 0

1190 next x1

1195 next y1

1196 print "finished initializing live cell list"

1200 print "randomly populate board with live cells"

1210 let g = 0 : rem cell generation

1220 let c = 0 : rem count of live cells

1230 for x1 = 2 to (m-2)

1240 for y1 = 2 to (m-2)

1250 if floor(rand(5)) then 1290

1260 let B(0,x1,y1) = 1

1262 let X(0,c) = x1

1262 let Y(0,c) = y1

1270 let c = c + 1

1280 plot x1,y1,"blue"

1290 next y1

1300 next x1

1310 print "finished randomly populating board with live cells"

1400 print

1410 print "disp gen: " + g + " live cells: " + c

1420 print "updating living cells in next generation"

1430 let g = g + 1 : rem increment generation

1440 let l = g % 2 : rem lambda oscillator ( 0, 1 )

1450 let l1 = (g + 1) % 2 : rem next generation board

1460 for i = 0 to (c-1) : rem with list of live cells

1470 for x1 = X(l,c) - 1 to X(l,c) + 1

1480 for y1 = Y(l,c) - 1 to Y(l,c) + 1

1482 if B(l,x1,y1) = 1 then 1700

1483 print "dead cell, checking for birth"

1485 let n1 = 0

1490 for x2 = x1 - 1 to x1 + 1

1500 for y2 = y1 - 1 to y1 + 1

1510 let n1 = n1 + B(l,x2,y2)

1680 next y2

1690 next x2

1700 PRINT "live cell"

1740 next y1

1750 next x1

1760 next i

6000 print "end" : end

initialize board

finished initializing board

initializing live cell list

finished initializing live cell list

randomly populate board with live cells

finished randomly populating board with live cells

disp gen: 0 live cells: 404

updating living cells in next generation

Line 1482 : TypeError: 'undefined' is not an object (evaluating 'VAR['B'][VAR['L']][VAR['X1']][VAR['Y1']]')

Mac OS X version 10.6.8

Safari version 5.1.9 (6534.59.8)

1:52 AM

Hi Mike.

Thanks for using QuiteBASIC!

You get the error on line 1482 because x1 and y1 are not defined.

That in turn is because X(1, c) and Y(1, c) are not defined.

On line 1180 it looks like typo. You probably meant: "let Y(1,y1)= 0".

But I'm guessing what you really want is something like:

1100 dim X(1,m*m)

1110 dim Y(1,m*m)

1130 for i = 0 to m*m-1

1150 let X(0,i) = 0

1160 let Y(0,i) = 0

1170 let X(1,i) = 0

1180 let Y(1,i) = 0

1190 next i

In the loops at lines 1470 and 1480, I'm guessing that you want something like this:

1470 for x1 = X(l1,i) - 1 to X(l1,i) + 1

1480 for y1 = Y(l1,i) - 1 to Y(l1,i) + 1

Note that "l1" is the previous generation and "l" is the next generation the way you have it.

I think there may be a few other issues, but I hope this helps get you get unstuck.

Nikko

8:35 PM

Post a Comment

<< Home