![]() |
|
Re-Dim (*solved*) - Printable Version +- Boriel Basic Forum (https://forum.boriel.com) +-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11) +---- Forum: Bug Reports (https://forum.boriel.com/forumdisplay.php?fid=15) +---- Thread: Re-Dim (*solved*) (/showthread.php?tid=433) |
Re-Dim (*solved*) - britlion - 2012-02-20 Boriel, can I use Dim in a SUB to reinitialise a global array? DIM grid (3,3) as uByte SUB reinitialiseGrid () DIM grid (3,3) as uByte => { {0,1,2,3}, {4,5,6,7}, {8,9,10,11}, {12,13,14,15} } END SUB Is that legal, or is it trying to make a local variable? Re: Re-Dim - britlion - 2012-02-20 Experimenting says it's a local copy ![]() Must be some way to reinitialise this. Is that a use for "byref" ? Re: Re-Dim - boriel - 2012-02-20 Passing arrays in a parameter is not supported (yet). The best way to do this is: Code: DIM MyArray As ... => ...
...
...
MyOtherArray = MyArray 'Copies MyArray into MyOtherArrayRe: Re-Dim - britlion - 2012-02-20 That will work. Didn't realise it was that simple to make a copy of the array - can make a working copy, and recopy over whenever we want to start again. (I was thinking I might have to do something manual with memcopy @address...) Very nice, Boriel. ZX Basic never ceases to amaze me as to how powerful it is - and you keep adding more! Re: Re-Dim - britlion - 2012-02-20 Code: DIM grid (4) as uByte => {0,1,2,3,4}
gridcopy=gridHmm. Okay. If I dim gridcopy first, that bit works - but 1> It fails to copy the data. the first print out of gridcopy still shows 0,0,0,0 2> It fails to compile at the second copy, when I try to reinitialise it again: 40: Array 'grid' has 1 dimensions, not 0 Code: DIM grid (4) as uByte => {0,1,2,3,4}
DIM gridcopy(4) as uByte
gridcopy=grid
ink 1
for n=0 to 4
print grid (n);" ";
next n
print
print
ink 2
for n=0 to 4
print gridcopy (n);" ";
next n
print
print
gridcopy(0)=10
gridcopy(1)=20
gridcopy(2)=30
gridcopy(3)=40
ink 1
for n=0 to 4
print grid (n);" ";
next n
print
print
ink 2
for n=0 to 4
print gridcopy (n);" ";
next n
gridcopy=grid
print
print
ink 1
for n=0 to 4
print grid (n);" ";
next n
print
print
ink 2
for n=0 to 4
print gridcopy (n);" ";
next nRe: Re-Dim - boriel - 2012-02-21 This is probably a bug (not a very tested feature, I guess). Will check it, and see... Re: Re-Dim - boriel - 2012-02-21 Ack: this is a bug. Fixing... Update: I think It's now fixed. Can you check it? (download 1.2.8 s785 or newer) Re: Re-Dim - britlion - 2012-02-28 I don't think so. 1.2.9-s798 grid = 0,1,2,3,4 gridcopy = grid print gridcopy gives 0,0,0,0,0 So no, data still isn't being copied from one array to the other. Re: Re-Dim - boriel - 2012-02-28 Ok. Try now, downloading 1.2.9s801. I've fixed more cases (complete test coverage). Re: Re-Dim - britlion - 2012-02-29 The above quoted code now does indeed show the array being copied correctly, changed correctly, and then recopied over correctly. Awesome. Thanks! |