![]() |
Re-Dim (*solved*) - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15) +---- Thread: Re-Dim (*solved*) (/showthread.php?tid=433) |
Re-Dim (*solved*) - britlion - 02-20-2012 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 - 02-20-2012 Experimenting says it's a local copy ![]() Must be some way to reinitialise this. Is that a use for "byref" ? Re: Re-Dim - boriel - 02-20-2012 Passing arrays in a parameter is not supported (yet). The best way to do this is: Code: DIM MyArray As ... => ... Re: Re-Dim - britlion - 02-20-2012 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 - 02-20-2012 Code: DIM grid (4) as uByte => {0,1,2,3,4} Hmm. 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} Re: Re-Dim - boriel - 02-21-2012 This is probably a bug (not a very tested feature, I guess). Will check it, and see... Re: Re-Dim - boriel - 02-21-2012 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 - 02-28-2012 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 - 02-28-2012 Ok. Try now, downloading 1.2.9s801. I've fixed more cases (complete test coverage). Re: Re-Dim - britlion - 02-29-2012 The above quoted code now does indeed show the array being copied correctly, changed correctly, and then recopied over correctly. Awesome. Thanks! |