Page 1 of 1

How to pass multi-dimensional arrays to a function

Posted: Tue Jul 11, 2017 1:10 pm
by Aureal
Hi, I've recently discovered that passing arrays to a function is possible. Well, I've decided to create a tetris clone, and, for the sake of optimization, I've put the sprites on a multi-dimensional array, storing them as strings. For example

Code: Select all

dim shared array(4, 5) as string

array(1, 1) = " # "
array(1, 2) = "###"

array(2, 1) = "#  "
array(2, 2) = "#  "
array(2, 3) = "#  "
And so on...

Then I would make a function to draw a random sprite on the screen based on an array "a", but, how do I declare an array in the parameters? and, how do I pass it?

Re: How to pass multi-dimensional arrays to a function

Posted: Tue Jul 11, 2017 9:41 pm
by burger2227
FUNCTION myarray(array()) 'passes all indices of the array

DIM SHARED array AS type can be used in main or SHARED array can be used in the Function declarations.