Re: Activating a Function in a Different Stack

2006-10-31 Thread Dave

Hi,

You have to be careful about using this as as in this stack,  
this card, etc.


There are a number of ways around it:

1.  Do this:

function CalledFromDiffStack

-- This refers to the stack etc. that called this one

put CalledFromThisStack into myValue
end CalledFromDiffStack


function CalledFromThisStack

-- this refers to the stack that called this function - e.g. the  
right one!


end CalledFromThisStack


2.  Use me instead of this stack etc. as in set the xxx of me to  
.



Also it's better to use the long name of this stack when calling the  
function in a different stack, don't know why, but the short name  
sometimes doesn't work.


Hope this Helps
Cheers
Dave


On 31 Oct 2006, at 01:45, Bridger Maxwell wrote:

Wow, thanks for the great response everyone.  I tried a few and I  
found that

the value function works the best.  I had actually been using virtual
properties in a few places instead of functions, but the problem  
then was

that I couldn't pass parameters to them.  Here is the final script:

   put Stack  where  quote into vStack
   put requestData  of  vStack into vRequest
   try
 put value(vRequest,vStack) into vReturn
   end try

One thing is still a little confusing though.  Calling a function  
like the
short name of the current stack return the name of the right  
stack, but a
request like the mouseLoc returns a value that is relative to the  
stack
that is retrieving the data, even if that stack isn't the top  
stack.  If the
mouseloc function is not relative to the top stack, and it is not  
relative
to the stack that the value is being requested from, how does it  
decide
which stack it is relative to and how can I know which functions  
are funny

like that?
Also one odd quirk I discovered was that when nesting value  
functions things

get weird.  i.e
value( (value(vRequest,vStack) ), vStack)
the short name of me would return Odyssey when the stack name was
Odyssey Sensors, and  that was the only function that would come  
close to

working.  Not important, but very mystifying.

 TTFN
   Bridger
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-31 Thread Dave

Opps! A typeo got into it! Should be:


1.  Do this:

function CalledFromDiffStack(p1,p2,p3)

-- This refers to the stack etc. that called this one

put CalledFromThisStack(p1,p2,p3) into myValue
return myValue
end CalledFromDiffStack


function CalledFromThisStack(p1,p2,p3)

-- this refers to the stack that called this function - e.g. the  
right one!


return VALUE
end CalledFromThisStack


Hi,

You have to be careful about using this as as in this stack,  
this card, etc.


There are a number of ways around it:

1.  Do this:

function CalledFromDiffStack

-- This refers to the stack etc. that called this one

put CalledFromThisStack into myValue
end CalledFromDiffStack


function CalledFromThisStack

-- this refers to the stack that called this function - e.g. the  
right one!


end CalledFromThisStack


2.  Use me instead of this stack etc. as in set the xxx of me to  
.



Also it's better to use the long name of this stack when calling the  
function in a different stack, don't know why, but the short name  
sometimes doesn't work.


Hope this Helps
Cheers
Dave


On 31 Oct 2006, at 01:45, Bridger Maxwell wrote:

Wow, thanks for the great response everyone.  I tried a few and I  
found that

the value function works the best.  I had actually been using virtual
properties in a few places instead of functions, but the problem  
then was

that I couldn't pass parameters to them.  Here is the final script:

   put Stack  where  quote into vStack
   put requestData  of  vStack into vRequest
   try
 put value(vRequest,vStack) into vReturn
   end try

One thing is still a little confusing though.  Calling a function  
like the
short name of the current stack return the name of the right  
stack, but a
request like the mouseLoc returns a value that is relative to the  
stack
that is retrieving the data, even if that stack isn't the top  
stack.  If the
mouseloc function is not relative to the top stack, and it is not  
relative
to the stack that the value is being requested from, how does it  
decide
which stack it is relative to and how can I know which functions  
are funny

like that?
Also one odd quirk I discovered was that when nesting value  
functions things

get weird.  i.e
value( (value(vRequest,vStack) ), vStack)
the short name of me would return Odyssey when the stack name was
Odyssey Sensors, and  that was the only function that would come  
close to

working.  Not important, but very mystifying.

 TTFN
   Bridger
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-30 Thread Ken Ray
On 10/29/06 7:13 PM, Marielle Lange [EMAIL PROTECTED] wrote:

 Never mind.  It is in parameters where that does not work.

Ah, but using pass-by-reference parameters DOES work:

on mouseUp
  put 1 into tTest[1]
  put 2 into tTest[2]
  updateArray tTest
  combine tTest using cr
  put tTest
end mouseUp

on updateArray @pTest
  put 3 into pTest[3]
end updateArray

When you click this button you get :

1
2
3

Tada! ok, Marielle said this first... ;-) 

Ken Ray
Sons of Thunder Software, Inc.
Web site: http://www.sonsothunder.com/
Email: [EMAIL PROTECTED]



___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-30 Thread Dar Scott


On Oct 30, 2006, at 12:51 PM, Ken Ray wrote:




Never mind.  It is in parameters where that does not work.


Ah, but using pass-by-reference parameters DOES work:


But you can't use pass-by-reference with send.

Dar

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-30 Thread Bridger Maxwell

Wow, thanks for the great response everyone.  I tried a few and I found that
the value function works the best.  I had actually been using virtual
properties in a few places instead of functions, but the problem then was
that I couldn't pass parameters to them.  Here is the final script:

   put Stack  where  quote into vStack
   put requestData  of  vStack into vRequest
   try
 put value(vRequest,vStack) into vReturn
   end try

One thing is still a little confusing though.  Calling a function like the
short name of the current stack return the name of the right stack, but a
request like the mouseLoc returns a value that is relative to the stack
that is retrieving the data, even if that stack isn't the top stack.  If the
mouseloc function is not relative to the top stack, and it is not relative
to the stack that the value is being requested from, how does it decide
which stack it is relative to and how can I know which functions are funny
like that?
Also one odd quirk I discovered was that when nesting value functions things
get weird.  i.e
value( (value(vRequest,vStack) ), vStack)
the short name of me would return Odyssey when the stack name was
Odyssey Sensors, and  that was the only function that would come close to
working.  Not important, but very mystifying.

 TTFN
   Bridger
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread Mark Smith
The only really convenient way to use functions in other stacks is to  
put those other stacks 'in use', so that their scripts are in the  
message path.


I'm not very clear on which stack is requesting what from where, but  
it sounds like you're loading a stack into a local machines memory  
from a remote server - so this should be possible.


Best,

Mark


On 29 Oct 2006, at 17:49, Bridger Maxwell wrote:


Hey,
 Is it possible to activate a function that resides in one stack,  
and get
the result from a different stack?  Right now I have it set up so  
that Stack
A gets a request for info from stack B over the Internet.  Lets  
pretend that
the request is the background color of this stack.  It puts that  
into a
variable called vWhat.  Then it executes do (get  vWhat  of  
Stack
B).  Then Stack A returns the data over the Internet.  This works  
well for
requesting properties, but I can't get it to activate a function  
and put the

result in the it variable.  Is it even possible?  Is there a send
equivalent for functions?

  TTFN
Bridger
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread Dar Scott


On Oct 29, 2006, at 9:49 AM, Bridger Maxwell wrote:


Is there a send
equivalent for functions?


Consider 'value()'.

You can specify an object.  (But this will not work on functions that  
return arrays, if you specify the object.)


Dar
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread Marielle Lange
 Is it possible to activate a function that resides in one stack,  
and get

the result from a different stack?


It is possible,

 
---

A. The send equivalent for functions according to the manual:

value(the name of me, card 1)

Stack A -  one button with the following script:
-
on mouseup
		 answer value(doSomething(  quote  one  quote  ,  quote  
 two  quote ), button 1 of stack stackA)

end mouseup

Stack B - one button with the following script:
-
function doSomething p1, p2
 return done, p1, p2
end  doSomething


 
---

B. Difficulties with this solution

The problem is that you cannot refer to any object on the card as all  
references are made relative to the calling object, not the one that  
receives the call.


As the doc says: If you specify an object, references to me in the  
expression are treated as references to the object. However, other  
object references are treated as though the handler were in the  
current object's script. For example, button 3 refers to button 3  
on the current card, not the card where the object is located.


Illustration of the problem.

Stack A -  one button with the following script:
-
on mouseup
		answer value(doSomething(  quote  one  quote  ,  quote   
two  quote ), button 1 of stack stackA)

end mouseup

Stack B - one button and a field:
-
function doSomething p1, p2
put p1,p2 into field 1
return done
end  doSomething

You will get an error. field 1 cannot be found, it doesn't exist on  
stack A. To use put p1,p2 into field 1 of this stack will not make  
any difference. This stack is stack A in this context. In stack B,  
you have to write your object references in full:


put p1,p2 into field 1 of card 1 of stack stackB

If your function on stack B calls a function or handler at card or  
stack level, the call will happen. But any reference to any object  
within that handler or function will be relative to the calling  
script (stack A), not stack B, with the same problem again.


So, to get the backgroundcolor propery of stackB you would have to write
	return the backgroundcolor of stack stackB -- or whatever the name  
of your stack is


 
---

C. The Custom Properties way

Your post suggests that you are already familiar with reading and  
writing custom properties across objects. You can use custom  
properties to read data the same way you can use them to send data.


Because of the nightmare of passing parameters with the value  
construct (you can easily end up spending 30 min. on this to get the  
quoting correct) as well as the problem that references are relative  
to the calling object, rather than the receiving one, I tend to  
prefer to use custom properties.


Stack A
-
on mouseup
send doSomething to stack stackB
		wait 1 tick (in case of, I believe that's not needed but I tend to  
add it)
		put the handlername_result of stack stackB  into tResult.   ---   
reading the custom property of another object

end mouseup

Stack B
-
on doSomething
--  do something
set the dosomething_result of me to the backgroundColor of this 
stack
end doSomething


That's clean... if there is any reference to any control in  
doSomething, then they will be interpreted relative to stack B, as  
expected. Note that I haven't tried that for files interacting over  
an internet connection but there is no reason to suppose it won't  
work (let me know if not).


 
---

D. Extension to functions

You don't need this, but I add it in case this is useful to anybody.  
What if you need to pass parameters to your functions? You can use  
the custom properties to send data as well.


Stack A
-
on mouseup
put the long id of stack stackB into tStackRef

set the p1 of tStackRef to one
set the p2 of tStackRef to two

send doSomething to tStackRef
wait 1 tick (I am not sure it is needed but I tend to add it)

		put the dosomething_result of tStackRef  into tResult.   ---   
reading the custom property of another object

end mouseup

Stack B
-
	on doSomething  --- It is not required to have the same name as the  

Re: Activating a Function in a Different Stack

2006-10-29 Thread Dar Scott


On Oct 29, 2006, at 3:07 PM, Marielle Lange wrote:


Stack A
-
on mouseup
send doSomething to stack stackB
		wait 1 tick (in case of, I believe that's not needed but I tend  
to add it)
		put the handlername_result of stack stackB  into tResult.
---  reading the custom property of another object

end mouseup

Stack B
-
on doSomething
--  do something
		set the dosomething_result of me to the backgroundColor of this  
stack

end doSomething


I think there is a shortcut.  You can use 'the result' for other than  
errors for custom commands.


Stack A
-
on mouseup
send doSomething to stack stackB
put the result into tResult.
end mouseup

Stack B
-
on doSomething
--  do something
return the backgroundColor of this stack
end doSomething

Another approach that makes sense for some kinds of functions is to  
define a virtual property on stack B.


And--I have recently learned--one way to call a function in another  
object is to temporarily move insert the object into the front  
scripts.  If there is not a problem with a name conflict this can  
also go into the back scripts, or if it is a stack, into the library  
scripts.  On my computer (1.25GHz G4) it takes less than 25  
microseconds to insert and remove an object, though I think stacks  
take longer for some reason.  I had been thinking of this in terms of  
a small library with possible name clashes, but this would work for a  
single function usage.


Stack A
-
on mouseup
insert the script of stack stackB into front
put f(x,y,z) into tResult.
remove the script of stack stackB from front
end mouseup

Stack B
-
function f x, y, z
--  do something
return done, x, y, z, the backgroundColor of this stack
end f

The meaning is not exactly the same a similar method using send  
because the message path is changed.


Dar
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread Marielle Lange
I think there is a shortcut.  You can use 'the result' for other  
than errors for custom commands.


I would bet you are right. But, but.. this could let us pass an array  
back to the calling script. Let's try.


Stack A
-
on mouseup
  send doSomething to button 1 of stack stackB
  put the result into aResult
  combine aResult using cr
  put aResult
end mouseup


Stack B
-
on doSomething
  get doSomething()
end doSomething
function doSomething
  put 1 into aTest[1]
  put 2 into aTest[2]
  put 3 into aTest[3]
  put 4 into aTest[4]
  return aTest
end  doSomething


Tadam...
1
2
3
4

This is a *splendid* tip. Thanks a bunch!

Marielle

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread Dar Scott


On Oct 29, 2006, at 4:35 PM, Marielle Lange wrote:


Tadam...
1
2
3
4


Yikes!  I was sure that didn't work!

Dar
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread Dar Scott


On Oct 29, 2006, at 4:42 PM, Dar Scott wrote:


On Oct 29, 2006, at 4:35 PM, Marielle Lange wrote:


Tadam...
1
2
3
4


Yikes!  I was sure that didn't work!


Never mind.  It is in parameters where that does not work.

Dar
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread Marielle Lange

Never mind.  It is in parameters where that does not work.


You are right. This works:

  on mouseup
put 1 into aTest[1]
put 2 into aTest[2]
get return_array(aTest)
put the result into aResult
combine aResult using cr
answer aResult
  end mouseup

  function return_array pArray
return pArray
  end return_array


But this doesn't (didn't really expect so)

Stack A
-
  on mouseup
put 1 into aTest[1]
put 2 into aTest[2]
get return_array(aTest)
send doSomething to button 1 of stack stackB
  end mouseup


Stack B
-
  on doSomething
put the result into aResult
combine aResult using cr
answer --  aResult
  end doSomething

 



What is exactly the scope of this the result?
According to the doc: The result function is set to empty when the  
current handler finishes executing.

This doesn't work either:

on mouseup
  put 1 into aTest[1]
  put 2 into aTest[2]
  get return_array(aTest)
  test_result
end mouseup
...
on test_result
  put the result into aResult
  combine aResult using cr
  answer --  aResult
end test_result

 



And about passing arrays as parameters, it looks like a challenge  
indeed.


This works:

Stack A
--
  put one into aTest
  send doSomething aTest to button 1 of stack stackB

This doesn't
Stack A
-
  put 1 into aTest[1]
  put 2 into aTest[2]
  send doSomething aTest to button 1 of stack stackB

 



Unsurprisingly, this doesn't work:
  set the array_data of button 1 of stack stackB to aTest

 



But this works:

Stack A
-
on mouseup
  put 1 into aTest[1]
  put 2 into aTest[2]
  set the customproperties of button 1 of stack stackB to aTest
  send doSomething to button 1 of stack stackB
end mouseup

Stack B
-
on doSomething
  put the customproperties of me into tArray
  .
end doSomething

Tadam ...
1
2

But I would stay away from this option... too dangerous to use!

 



Of interest... this works as well

Stack A
-
on mouseup
  put 1 into aTest[1]
  put 2 into aTest[2]
  set the customproperties[test] of button 1 of stack stackB to  
aTest

  send doSomething to button 1 of stack stackB
end mouseup

Stack B
-
on doSomething
  put the customproperties[test] of me into tArray
  ...
end doSomething


Multidimensional arrays can be used:
(simply because the array indexes are converted into a string)
  put 1 into aTest[1,2,3]
  put 2 into aTest[2,2,3]
 ...
  combine aResult using cr and tab

Thanks for the brainstorming and the ideas!
Marielle

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread Marielle Lange

Note that the post has now been archived on the code website:
http://codes.widged.com/?q=node/724
... with code coloring.

Enjoy,
Marielle

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread Dar Scott


On Oct 29, 2006, at 6:13 PM, Marielle Lange wrote:


What is exactly the scope of this the result?
According to the doc: The result function is set to empty when the  
current handler finishes executing.


I have tried grabbing 'the result' in logging functions, but found I  
needed to pass it as a parameter.  In most cases, I get the result in  
the line following the command that generated it.


I'm not sure, but I think 'the result' is set to empty at the _start_  
of handlers and of some built-in functions and commands.


Note this:
**
on mouseUp
  test
  put the result
end mouseUp

on test
  put f(5) into z
  put 2into y
end test

function f x
  return x+x
end f
**
Upon click 10 is put into the message box.

Dar
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Activating a Function in a Different Stack

2006-10-29 Thread J. Landman Gay

Dar Scott wrote:

I'm not sure, but I think 'the result' is set to empty at the _start_ of 
handlers and of some built-in functions and commands.


Lots of built-in commands and functions set the result, and those will 
replace any current value immediately. Otherwise, the docs say the 
result is set to empty when the currently executing handler ends. I 
think this means when the execution queue is done.


--
Jacqueline Landman Gay | [EMAIL PROTECTED]
HyperActive Software   | http://www.hyperactivesw.com
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution