Pass command

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Pass command

Post by chris25 » Thu Dec 05, 2013 11:46 am

Ok straight to the point, why does this not work please? OBJECT: Click button and insert text in both fields just to practise. The name of the button is well "button", Text fieldA is on card 1, text fieldB is on card 1. I first made fieldB a group because that is further down the message path. When this failed I made it a background group to put it further beyond the card. The lecture is clear: If I have missed something then it was not in the lecture.

In the Button:

Code: Select all

on mouseUp
   put "ugh" into fld "fieldA"
   pass mouseup
end mouseUp
In "FieldB"

Code: Select all

on mouseUp
  if the short name of the target is "button" then
   put "also in here" into fld "fieldB"
  end if
end mouseUp
regards
chris

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Pass command

Post by bangkok » Thu Dec 05, 2013 11:57 am

You'll see the light by reading this amazing paper :

http://www.fourthworld.com/embassy/arti ... _path.html

:D

you could catch the "mouseup" message, passed from the button... ON THE CARD (not another control, unless you explicitly send the message to the other control).

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

Re: Pass command

Post by dunbarx » Thu Dec 05, 2013 2:42 pm

What Bangkok said and what Richard authored.

Chris, you need to look carefully at Richard's charts at the card level. Note that many controls can be members of many groups, and all those objects can be members of a card. But only the card itself is further along in the hierarchy than any or all of those disparate objects or groups. So messages never pass naturally among or between those objects themselves, they all being at the same level. They all pass to the card.

Craig

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: Pass command

Post by chris25 » Thu Dec 05, 2013 3:50 pm

So yes i have this paper already referenced and have stumbled through it a few times. I thank you, but this paper did not tell me HOW to use the send in a PRACTICAL demonstration. So after further study I managed to come up with this example attempt which I see is wrong. Now Craig, in simple layman terms, messages can NOT be sent between objects or groups or anything if they are on the same card? This is how I interpret what you said. am I wrong?

regards
chris

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

Re: Pass command

Post by dunbarx » Thu Dec 05, 2013 3:58 pm

Just the opposite. "Send" can send a message to any object at any level to any card in any stack anywhere in the universe. It is one of the tools that is used to bypass the native hierarchy, sending instead to an explicitly defined target. You can, in a stack script, send a message all the way back down to a control. You can send a message that worked its way up from a control back on down.

Your homework is to write a simple gadget that does this...

Craig

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: Pass command

Post by chris25 » Thu Dec 05, 2013 4:06 pm

That's what I was trying to do - some homework on this. Obviously getting it wrong, and that after trying to understand why it would be used in what kind of situation. This little exercise I thought would be the darnest simplest thing to do - so getting it wrong only means that I am no understanding why it is wrong...why is this wrong would teach me more than trying to thumble my way through complex paragraphs and documentation.
kind regards
chris

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Pass command

Post by Klaus » Thu Dec 05, 2013 4:30 pm

Hi Chris,

in your example above your are NOT SENDing anything at all!
You are just relying on the message herarchie, which does not work that way!
SENDing means to actually use the keyword "send" 8)

Hint: No editable field will receive "mouse" messages" like "mouseup" etc!

A littel example...

Given 2 Buttons on a card: B1 and B2

B1 has this script:

Code: Select all

on mouseup
  dothebeep
end mouseup

command dothebeep
 beep 3
end dothebeep
So it beeps 3 times when clicked.

Script of button B2

Code: Select all

on mouseup
  send "dothebeep" to btn "B1"
end mouseup
Will also beep 3 times :D

You can send ANYTHING to ANYWHERE as long as the address is correct!
..
send "whatever" to btn "a button" of grp "a cool group" of cd "name of card here" of stack "another stack"
...


Best

Klaus

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: Pass command

Post by chris25 » Thu Dec 05, 2013 4:47 pm

Ok there has been some confusion in postings. I am not practising the send command, (I am learning that right now), no, I was practising the PASS command. And the key phrase I read said this:... Anytime you want a message to be handled in an object and in another script for example further down the message path, then you use the Pass command followed by the name of the handler that it is in. Completely misunderstood by me I know. I think I did a good job of pointing the fieldB back to the button and with the same mouse up handler of course. So this is what I did not understand.
chris

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Pass command

Post by Klaus » Thu Dec 05, 2013 5:02 pm

Hi Chris,

sorry, I was referring to your:
but this paper did not tell me HOW to use the send in a PRACTICAL demonstration.
OK, but your very first example dow not work because the button and the field are on the SAME hierachie level.
That means whatever you pass, it will NOT reach the other object!

Example how to use pass...

1. You want every mouseclick to play a sound
2. You do not want to write this in every mouseup handler in your buttons
3. So you put this into the CARD script:

Code: Select all

on mouseup
  play (specialfolderpath("desktop") & "/name of cool sound.wav")
end mouseup
4. Now you simply PASS all mouseups in oyur buttons on the card to hear the sound
Button "click me"

Code: Select all

on mouseup
  answer "Now you will hear a sound!"
  pass mouseup
end mouseup
So the MOUSEUP will be passed to the next level of hierarchie (the card in this case)
and THAT mouseup script will also be executed.


Best

Klaus

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Pass command

Post by SparkOut » Thu Dec 05, 2013 5:04 pm

Hi Chris,

Where you have gone wrong is to misunderstand the nature of the PASS statement. A message is generated by an event happening with one of the controls of a card of a stack. That message moves along the message path until it it trapped by a handler, which takes some action according to its script. If the script PASSes the message, it does not get spread around to all other controls, but it will also continue on until trapped by another handler along the path or until it reaches the end of the path without any handler catching it and the engine eats it.

In your case the PASS statement will not send the message on to fieldB because fieldB is not in the message path of the message from the button. Making fieldB a member of a group does not put fieldB further down the message path for the button, because the button is not part of the same group. If you made the button part of the same group as fieldB, and MOVED THE SCRIPT from fieldB to the group, THEN you will find the message is handled after being passed by the button.

In your case the path is BUTTON -> CARD -> STACK -> etc.
If you group both the button and fieldB then the path becomes BUTTON -> GROUP -> CARD -> STACK -> etc. (with possible extra consideration if you make it a background group). In this case, you will have to move the script to be caught to the group, as you can see the message, having been passed, goes on along the path, it doesn't make a sideways turn to check the script of fieldB. Of course, you could leave out the group altogether and put the second mouseUp handler on the card script, but that would then trigger the script for any mouseUp message generated for any control on the card that does not already trap it without passing.

Is that any clearer?

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: Pass command

Post by chris25 » Thu Dec 05, 2013 7:15 pm

Firstly Klaus, thankyou Klaus. That is what I imagined, but saying that the fields and button are on the same hierarchal level I realized and therefore for that reason made it a group 'believing' that this was setting it on a different level down message path, thankyou for the practical example, this is a useful one.

sparkout thanks, yes I do understand already about what you said in the first paragraph, absolutely, but how It is explained in what I read leaves vitally important information out, namely what you wrote in the second and third paragraph, it really is now simply that there is lot open to misinterpretation by a beginner, ambiguity floods the written stuff, I am only now just realizing this when reading documents and example tutorials - I really get it now thanks to what you said. Thankyou.

kindest regards
chris

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

Re: Pass command

Post by dunbarx » Thu Dec 05, 2013 7:43 pm

Chris.

Think you have gotten over the hump yet? I do. This does not mean you are an expert, it means you finally have a feel for the environment. Just a few more weeks and all your questions will start being of an entirely different type, dealing with power and technique, not the swamp you thought you were mired in.

Craig

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: Pass command

Post by chris25 » Thu Dec 05, 2013 10:41 pm

Hi Craig, kind of you to ask that. Honestly, I think I was on the verge twice of giving in, but those feelings were half-hearted - more like a bad mood moment. Yes I definitely have gotten used to the environment and the logistics and probably quite a few foundations laid. But building the bricks into something tangible and workable is difficult when you have to scrounge for morsels of cement all the time :D . Sorry about the constant nagging for answers, but give me a 2 week 3 hour daily video crash course for 100 euros and I would have jumped at it, pity that some of us are priced out of the valuable tuition that I have read in my emails, I would have joined, but for the..... :(

Kindest regards
chris

Post Reply