# Quick yes or no question on variable arrays

3 replies to this topic

### #1 jbs30000OFFLINE

jbs30000

Moonsweeper

• 472 posts

Posted Sat Oct 16, 2010 12:48 AM

It's been a while since I've done this so I figured I'd better double check because my memory is crap.

If I go
dim MyArray=a

Then MyArray[0] is a and MyArray[1] is b, correct?

### #2 Random TerrainOFFLINE

Random Terrain

Visual batari Basic User

• 28,789 posts
• Controlled Randomness
Replay Value
Nonlinear
• Location:North Carolina (USA)

Posted Sat Oct 16, 2010 5:31 AM

I don't know for sure, but I thought arrays were read-only with bB:

http://www.randomter...html#dataarrays

### #3 SeaGtGruffOFFLINE

SeaGtGruff

• 5,566 posts
• Location:South Carolina, USA

Posted Sat Oct 16, 2010 1:31 PM

It's been a while since I've done this so I figured I'd better double check because my memory is crap.

If I go
dim MyArray=a

Then MyArray[0] is a and MyArray[1] is b, correct?

Yes, that's right. The number in square brackets is the offset to the starting address, so an offset of 0 gives you the starting address (a). The assembly equivalent is

```   ; MyArray[0]
LDX 0
LDA MyArray,X
; MyArray[1]
LDX 1
LDA MyArray,X
```
Michael

### #4 SeaGtGruffOFFLINE

SeaGtGruff

• 5,566 posts
• Location:South Carolina, USA

Posted Sat Oct 16, 2010 1:50 PM

I don't know for sure, but I thought arrays were read-only with bB:

If you dim an array to ROM, it will be a read-only array. But if you dim an array to RAM, it will be a read/write (variable) array.

Note that if you dim an array to expansion RAM that requires separate read and write addresses, you'll need to either dim the array twice-- once for writing, and once for reading-- or you'll need to modify the index as needed if the expansion RAM is small enough.

For example:

```   rem dim a Superchip array for writing and reading
dim w_MyArray=\$F000
dim r_MyArray=\$F080
w_MyArray[12]=rand
w_MyArray[12]=r_MyArray[12]+1
```
```   rem modify the index instead of dimming twice
dim MyArray=\$F000
rem use index 0 to 127 for writing
rem use index 128 to 255 for reading
MyArray[12]=rand
MyArray[12]=MyArray[140]+1
```
In the second example, note that 140=12+128, so it does the same thing as the first example (add 1 to the element with index 12). However, the second example/method is harder for the reader to understand, and it will work only for Superchip expansion RAM (since the Superchip has 128 bytes of RAM, so there are a total of 256 write and read addresses).

Michael

#### 0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users