I'm having trouble initializing an array in one function and then being able to access the array content from another function. Here's an example.
mainCalc is called from a button handler. mainCalc in turn calls initializeIt to initialize myArray[].
mainCalc than calls checkSomething. Unfortunately, the values in myArray that were initialized in initializeIt are not available to the function checkSomething.
I'm using LiveCode build 7.0.3
Any suggestions will be appreciated.
Thanks!
Howard
var sAB
array myArray
var myResult
function initializeIt
put 7 into myArray[1]
put 8 into myArray[2]
put 2 into myArray[3]
end initializeIt
function checkSomething pFreqA,pFreqB
put myArray[2] into sAB
-- write some code
return sAB
end checkSomething
function mainCalc
get initializeIt()
put 4 into sA
put 876 into sB
put checkSomething(sA,sB) into myResult
-- lots of code lines follow
end mainCalc
Domain problem
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Domain problem
hi drhoward
when you initialize script local variables (the ones outside of any handler in a script) you use "local". And you don't put the type, Livecode does that automatically for you.
try this
I find it helpful to prepend local variables with t, script local variables with s, global variables with g. That way you always know what type of variable you are dealing with.
Kind regards
Bernd
when you initialize script local variables (the ones outside of any handler in a script) you use "local". And you don't put the type, Livecode does that automatically for you.
try this
Code: Select all
local sAB
local myArray
local myResult
function initializeIt
put 7 into myArray[1]
put 8 into myArray[2]
put 2 into myArray[3]
end initializeIt
function checkSomething pFreqA,pFreqB
put myArray[2] into sAB
-- write some code
return sAB
end checkSomething
function mainCalc
get initializeIt()
put 4 into sA
put 876 into sB
put checkSomething(sA,sB) into myResult
-- lots of code lines follow
end mainCalc
Kind regards
Bernd
Re: Domain problem
Thank you! Using local works.