How to check whether a message port exists

Find quick help here to get you started with Hollywood
Post Reply
zylesea
Posts: 232
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

How to check whether a message port exists

Post by zylesea »

How to check whether a message port actually is existing or not. If a message gets send to a message port that does not exist, the script unfortunately aborts.
Do hollywood functions return a value on execution? Would something similar to
if sendmessage ("BLA", "BLUP") = false then Debugprint ("failed to send message") work? This particular syntax doesn't work at least, but something like that maybe as you oftenly use with C?
User avatar
airsoftsoftwair
Posts: 5834
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to check whether a message port exists

Post by airsoftsoftwair »

No, Hollywood functions usually don't return a value indicating error or success. But you could encapsulate the call to SendMessage() inside an ExitOnError() clause and then check if it worked or not, i.e.

Code: Select all

ExitOnError(False)
SendMessage(...)
err = GetLastError()
ExitOnError(True)
If err <> #ERR_NONE Then DebugPrint("Error sending message....")
A function like FindPort() would be nicer though, but still this wouldn't guarantee that SendMessage() succeeds because the port might go away at any time. So even if a function like FindPort() returned to TRUE, it could still happen that the port goes away between FindPort()s return and the call to SendMessage(). I guess that's why I didn't implement a FindPort() functionality because the result would always be unreliable.
zylesea
Posts: 232
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

Re: How to check whether a message port exists

Post by zylesea »

Thanks Andreas. As always your answer was pretty helpful.
Post Reply