Hello,
I am wondering how to define a local array within a function.
I tried this
LOCAL DIM myArray[10];
but this does not work. If i left out the word LOCAL, then it looks ok. Is it normal? Is myArray still local?
Secondly, is it ok to return a local array from a function like this:
FUNCTION BuildSequence: pLevel
// These values are defined LOCAL:
// pLevel
DIM tSequence[pLevel+2];
FOR i = 0 TO pLevel+1
tSequence[i] = RND(7);
NEXT
RETURN tSequence
ENDFUNCTION
How should the "receiving" variable look like?
Thanks for your help.
François
FUNCTION foo:
LOCAL arr[]
DIM arr[120]
You can't return an array. But arrays are passed by reference, thus you can use an array as a parameter and change the contents within the function.
Marvellous, it even better.
Thanks for your quick answer.
François
example:
//Create a array
LOCAL MyArray[]
DIM MyArray[12]
//fill something into it
SetSomething(MyArray[])
WHILE TRUE
// Print all
FOR i = 0 TO LEN(MyArray[])-1
PRINT MyArray[i], i*20,10
NEXT
SHOWSCREEN
WEND
END
FUNCTION SetSomething: Array[]
// from 0 to Arraysize -1
FOR i = 0 TO LEN(Array[])-1
Array[i] = i // fill in
NEXT
ENDFUNCTION
Thanks for the exemple... it really helps :)
No problem :)