Sending a message

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
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Sending a message

Post by Simon Knight » Tue Sep 28, 2010 2:47 pm

I am building an application that is going to use a number of different control types all with the same behavior script. One of the scripts in the behavior script will be "initialise". How would you recommend I approach the problem of sending the "initialise" message to only those controls that use the behavior script. My initial thoughts are:
1) Use a manual list : simple but a bit of a kludge, I'd rather do better.

2) Look through all the controls on the UI stack and send the message to ones that meet a criteria. I suppose my question is what criteria? For example is it possible to select objects based on the name of their associated behavior button? Should I use a custom property in each control.

Any thoughts?
best wishes
Skids

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

Re: Sending a message

Post by Klaus » Tue Sep 28, 2010 3:02 pm

Hi Simon,

I would loop through ALL objects and use a "try" structure to get rid or errors :D

Something like this:

Code: Select all

...
repeat with i = 1 to the num of controls ## of cd x of stack y
  try 
    send "intitialize" to control i ## of ...
  ## Or use "dispatch", see the docs
  catch errornum
   ## Do nothing on error!
  end try
end repeat
...
Best

Klaus

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Sending a message

Post by Simon Knight » Tue Sep 28, 2010 3:24 pm

Thanks Klaus,

I will give it a go.
best wishes
Skids

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Sending a message

Post by FourthWorld » Tue Sep 28, 2010 3:40 pm

FWIW, if the objects in question are groups you could use the openControl or preOpenControl messages.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Sending a message

Post by dunbarx » Tue Sep 28, 2010 9:20 pm

Hi.

You already answered your question. The criterion you could use is the behavior property itself, which takes the form of a long ID.

So loop through all the controls, and send the message if the behavior of the control is the long ID of the button containing the initialize script:

repeat with y = 1 to the number of controls
if the behavior of control y = yourLongID then send "initialize" to control y
end repeat

Craig Newman

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Sending a message

Post by Simon Knight » Wed Sep 29, 2010 8:14 am

Thanks Craig,

I thought it must be possible but I didn't know what the syntax would be.

A supplementary question: I am using a splash stack and this will be the stack that is compiled. The objects that need to receive the "initialise" message are on other stacks. I would like to have the initialise message sent when the user opens the application so I was wondering at what point are the other stacks available for use or to put it another way will I be able to issue the initialise message from the open stack handler of my splash stack?

Simon
best wishes
Skids

Post Reply