Script widgets: How to emit a message than can be managed in widget's script?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Script widgets: How to emit a message than can be managed in widget's script?

Post by stam » Sun Aug 27, 2023 11:23 am

Hi all,

Does anyone know how to emit a message from a script widget that can be captured in the widget's script?
By this I mean emitting a message like 'textChanged' in text fields - where you can then edit the widget's code in the IDE to respond to the message?
Does anyone know if this is possible?

Many thanks
Stam

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 192
Joined: Thu Apr 18, 2013 2:48 pm

Re: Script widgets: How to emit a message than can be managed in widget's script?

Post by livecodeali » Sun Aug 27, 2023 3:48 pm

Do

Code: Select all

send "textChanged" to the owner of me
in the script widget script

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Script widgets: How to emit a message than can be managed in widget's script?

Post by stam » Mon Aug 28, 2023 12:10 am

Thanks Ali

I'm doing that already but was asking if it's possible to respond to the message inside the widget instead of it's owner, pretty much like textChanged would function in a field's script... I'm guessing no then ;)

bwmilby
Posts: 442
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Script widgets: How to emit a message than can be managed in widget's script?

Post by bwmilby » Tue Aug 29, 2023 1:27 am

Wouldn’t that just be calling the handler directly? Are you wanting to do some work in the widget before passing the message for possible additional work outside?
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Script widgets: How to emit a message than can be managed in widget's script?

Post by stam » Tue Aug 29, 2023 3:23 am

bwmilby wrote:
Tue Aug 29, 2023 1:27 am
Wouldn’t that just be calling the handler directly? Are you wanting to do some work in the widget before passing the message for possible additional work outside?
No it's not the same.
If a certain action occurs, then a message would be emitted that can be captured by a developer in the widget's script to react to It,
As mentioned, the best analogy would be implementing a 'textChanged' handler in a text field. It is more practical to have this in the text field's script rather than the card script.

What Ali recommends is what Bernd recommended to me previously and what I've already implemented, and certainly works.
But you have to capture the message in the card script rather than the widget's (i.e. after adding to a card), which is like having a textChanged message in the card script that has to act based on the id of the text field that emitted the 'textChanged' message and the content of the message.
It works, but it's not the most practical/intuitive way of doing this...

But sounds like this probably isn't possible at present :(

bwmilby
Posts: 442
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Script widgets: How to emit a message than can be managed in widget's script?

Post by bwmilby » Tue Aug 29, 2023 1:57 pm

Ok, I understand now. You want an equivalent to the LCB

Code: Select all

post “messageName”
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 192
Joined: Thu Apr 18, 2013 2:48 pm

Re: Script widgets: How to emit a message than can be managed in widget's script?

Post by livecodeali » Tue Aug 29, 2023 6:25 pm

stam wrote:
Tue Aug 29, 2023 3:23 am
But you have to capture the message in the card script rather than the widget's (i.e. after adding to a card)
This isn't the intention- you are supposed to be able to handle the message in the widget object's script. I'll have to check but potentially this is a dp 5 bug which will be fixed in dp 6.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Script widgets: How to emit a message than can be managed in widget's script?

Post by stam » Thu Aug 31, 2023 9:58 am

livecodeali wrote:
Tue Aug 29, 2023 6:25 pm
This isn't the intention- you are supposed to be able to handle the message in the widget object's script. I'll have to check but potentially this is a dp 5 bug which will be fixed in dp 6.
Please ignore my previous statement - completely my error.
While I had been handling the message in the card script perhaps misunderstanding Bernd's advice, I've finally had some time to check (day job getting in the way!) and it works perfectly in widget's script. I even get the option to add the handler from the left sidebar in the SE!
Loving script widgets even more!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”