the purpose of sendmessage to an object..

BlitzMax Forums/BlitzMax Beginners Area/the purpose of sendmessage to an object..

Hardcoal(Posted 2016) [#1]
Hi.
What is the purpose and use of SendMessage to an object..?


Hardcoal(Posted 2016) [#2]
I guess ill have to figure it on my own


Kryzon(Posted 2016) [#3]
There isn't any function like that in the documentation. Where did you read it?

Messaging is, as far as I know, an abstraction. Like events or signals.
You send a message to an object, and that object will try to recognise and react to that message.

http://programmers.stackexchange.com/a/140607

A simple example is: user presses a button and in the event handler function of the button you send a message like "button was pressed" to one or more objects, and that(those) object(s) can then react and do something (quit the application, create something etc.).


Brucey(Posted 2016) [#4]
SendMessage is a method of Object.

Signature is
SendMessage:Object(m:Object, s:Object)



Hardcoal(Posted 2016) [#5]
So how do you read the message?
What is the opposite command?


Kryzon(Posted 2016) [#6]
If you look at the source, there is no use of that SendMessage function.
https://github.com/maxmods/brl.mod/search?utf8=%E2%9C%93&q=bbObjectSendMessage


LT(Posted 2016) [#7]
Actually, it works fine. It's basically like calling a generic method. The passed object can store your arguments, if desired. I use it for testing purposes, mostly.


TomToad(Posted 2016) [#8]
I think it is used by the compiler. bbObjectSendMessage appears in many .s files.


Brucey(Posted 2016) [#9]
I think it is used by the compiler.

I am not aware of it being used anywhere in the standard distribution.

It is a generic method available to all Objects to implement as they wish.
What you do with it is completely up to you - just like when you implement ToString() for your type... you can return whatever text you want.


Hardcoal(Posted 2016) [#10]
I just still didn't get how exactly you use it..

Anyone care to post an example?


Derron(Posted 2016) [#11]



As you see: I call "SendMessage" for all wheels, regardless of "TFrontWheel" or not.
This is possible, because "Method SendMessage:object(message:object, param:object)" is defined for every object.
In "TFrontWheel" I did a simple override of that method to react to it individually.


bye
Ron


Derron(Posted 2016) [#12]
And this is the extended version showing that you can use the same method for various things:



You see "message" or "param" could be everything (except simple integers/floats/doubles - they would need to get wrapped in a type first).


bye
Ron


Hardcoal(Posted 2016) [#13]
Tnx Derron Ill take a look and see if its useful to me in some way