Another Sly Laboratories innovation
bobs at twft.com
Fri Dec 30 17:07:00 CST 2011
I think I just came up with a way to get information from another stack that otherwise would be invisible to the stack I am working on. In this case I wanted a property of a card field on a card in a stack that was not the one I was working with. Further, I wanted to be able to change the card field, the card and even the stack on the fly without having to make those stacks aware of the controlling stack.
I knew the short name of the field. I needed the long ID of that field. The trouble is, the object belonged to a group that I did NOT know. Also, the global had not been declared in the target stack, and since I wanted this stack to work with any stack I used it on, I didn't want to have to make every one of those stacks aware of the global to use it.
I did this in a menu of card fields on the target card:
global gWhichField, gWhichCard, gWhichStack
--> all handlers
on menuPick pChosen
put pChosen into theField
send "global gWhichField;put the long id of " & theField & " of " & gWhichCard & " into gWhichField" to gWhichStack
This updated the global gWhichField in the current stack without having to know the ID of the group it belonged to. Notice in the send command I actually sent two commands, the global declaration and the actual command. The dictionary does not mention that you can do this. I am not sure anyone ever thought of trying. I don't think it will work with dispatch, as the key to this working is that send temporarily makes the target stack the defaultStack. I suppose you could apply this same technique of sending multiple commands to solve some other sticky problems.
It is quite possible that I drank too much coffee and am solving the problem some long, convoluted and completely unnecessary way, so feel free to chide me if I have.
More information about the use-livecode