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
Referencing a n array from a function
-
- Posts: 4
- Joined: Sat Oct 05, 2024 7:41 pm
- My devices: Ipad
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Referencing a n array from a function
There are different ways to access array from function. This program sample demonstrates them:
Function "func1" accepts array as a function parameter.
Function "func2" directly access the global array.
Output of this program is:
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 "func2" directly access the global array.
Output of this program is:
Code: Select all
1.2
3.4
-
- Posts: 4
- Joined: Sat Oct 05, 2024 7:41 pm
- My devices: Ipad
Re: Referencing a n array from a function
Thanks mate.
- Dutchman
- Posts: 851
- Joined: Mon May 06, 2013 9:21 am
- My devices: iMac, iPad Air, iPhone
- Location: Netherlands
- Flag:
Re: Referencing a n array from a function
The example has been added to the PDF-manual.
See https://nitisara.ru/forum/viewtopic.php ... 616#p15616
See https://nitisara.ru/forum/viewtopic.php ... 616#p15616