Page 1 of 1

Referencing a n array from a function

Posted: Fri Oct 11, 2024 8:25 pm
by Python27au
G’day,

Can anyone tell me how to reference a main code array from within a function?
I have several functions that are passed a set of values. The functions are supposed to use the values to lookup an array and return the value of the array. Sort of like this:

DIM array(7,7,3)

Def Func1(a,b,c)
“Set up”
Result1=array(a,b,c)
“Do something with result1”
Func1=result2
End def

MainLoop:
“Calcuate some values a, b, c)
Result=Func1(a,b,c)
IF Result=1 THEN
Do something
ELSE
Do something else
END IF

Re: Referencing a n array from a function

Posted: Fri Oct 11, 2024 9:48 pm
by Mr. Kibernetik
There are different ways to access array from function. This program sample demonstrates them:

Code: Select all

dim array(10,10)
array(1,2)=1.2
array(3,4)=3.4

def func1(ar(,),x,y)
return ar(x,y)
enddef

def func2(x,y)
return .array(x,y)
enddef

print func1(array,1,2)
print func2(3,4)
Function "func1" accepts array as a function parameter.
Function "func2" directly access the global array.

Output of this program is:

Code: Select all

1.2
3.4

Re: Referencing a n array from a function

Posted: Fri Oct 11, 2024 11:53 pm
by Python27au
Thanks mate.

Re: Referencing a n array from a function

Posted: Tue Oct 15, 2024 1:09 pm
by Dutchman
The example has been added to the PDF-manual.
See https://nitisara.ru/forum/viewtopic.php ... 616#p15616