How not to copy an Array

BlitzMax Forums/BlitzMax Beginners Area/How not to copy an Array

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Oops, I wrote some code similar to the example below to make a copy of an array and then modify the copy. However, it just points to the original array (obviously doh!) and doesn't copy it, so this code outputs 10,10 - not 10,1. However, comment out Local a2[]=a1 and uncomment the line below and it will work because using slices makes a copy of the array. Just thought I'd post this so other beginners won't make the same mistake that I did.

Strict
Local a1[] = [1,2,3,4,5]
Local a2[]=a1
'Local a2[]=a1[0..Len(a1)]

a2[0] = 10
Print a2[0]
Print a1[0]