how are variables passed from functions?

Bob Sneidar bobsneidar at iotecdigital.com
Fri Nov 14 14:35:05 EST 2014


Not sure what you are asking, but here is how functions work. 

As soon as the script execution encounters a return command, the function terminates and returns control to the calling handler. Nothing that comes after the return in the function is executed. 

Now here is what weirds me out:

on mouseUp
  put test1()
end mouseUp

function test1
   put "blah" into myVar
   put test2() into myVar2
   put test3() into myVar3
end test1

function test2
   return "blah2"
end test2

function test3
   return "blah3"
end test3

This produces “blah3”. Really? So… the last value *ANY* function returns becomes the value returned of any function that called it unless specified otherwise. Is this the intended behavior? That is frightening and unnerving. 

Bob S


> On Nov 14, 2014, at 08:20 , Tiemo Hollmann TB <toolbook at kestner.de> wrote:
> 
> Hi Craig,
> perhaps I didn't expressed myself correct, I'm not a native speaker.
> For me the result seems the same, if I put a return myVar2 at the end of function foo1 or not (see below). The intermediate function is terminated AFTER the call of the second function at the end.
> My original script works without a return in foo1. My question was, if it is a good or bad practice if I would add this return, just for "safety reasons" to be sure anything is returned in case I would change anything, e.g. I would replace the call of function foo2 by any other structure.
> Tiemo
> 
> --Btn script
> on mouseUp
>    put foo1() into myVar1 
> end mouseUp
> 
> --script in stack
> function foo1
>   put foo2() into myVar2 
>   return myVar2 -- return statement yes or no?
> end foo1
> 
> function foo2
>   return "Test"
> end foo2



More information about the use-livecode mailing list