FAQ  •  Register  •  Login

Re-Dim (*solved*)

<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Mon Feb 20, 2012 4:42 pm

Re-Dim (*solved*)

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?
<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Mon Feb 20, 2012 5:03 pm

Re: Re-Dim

Experimenting says it's a local copy :(

Must be some way to reinitialise this. Is that a use for "byref" ?
<<

boriel

Site Admin

Posts: 1147

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Feb 20, 2012 7:19 pm

Re: Re-Dim

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 MyOtherArray

Is that what you meant?
<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Mon Feb 20, 2012 9:03 pm

Re: Re-Dim

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!
<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Mon Feb 20, 2012 9:24 pm

Re: Re-Dim

  Code:
DIM grid (4) as uByte => {0,1,2,3,4}
gridcopy=grid

Cannot assign an array to an escalar variable

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}
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 n

 
<<

boriel

Site Admin

Posts: 1147

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Feb 21, 2012 1:24 am

Re: Re-Dim

This is probably a bug (not a very tested feature, I guess).
Will check it, and see...
<<

boriel

Site Admin

Posts: 1147

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Feb 21, 2012 2:44 pm

Re: Re-Dim

Ack: this is a bug. Fixing...

Update: I think It's now fixed.
Can you check it? (download 1.2.8 s785 or newer)
<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Tue Feb 28, 2012 5:08 pm

Re: Re-Dim

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.
<<

boriel

Site Admin

Posts: 1147

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Feb 28, 2012 10:39 pm

Re: Re-Dim

Ok. Try now, downloading 1.2.9s801. I've fixed more cases (complete test coverage).
<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Wed Feb 29, 2012 2:03 pm

Re: Re-Dim

The above quoted code now does indeed show the array being copied correctly, changed correctly, and then recopied over correctly.

Awesome. Thanks!

Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO