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?
How to check whether a message port exists
- airsoftsoftwair
- Posts: 5834
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: How to check whether a message port exists
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.
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.
Code: Select all
ExitOnError(False)
SendMessage(...)
err = GetLastError()
ExitOnError(True)
If err <> #ERR_NONE Then DebugPrint("Error sending message....")
Re: How to check whether a message port exists
Thanks Andreas. As always your answer was pretty helpful.