The following is part of an ongoing series of basic tutorials for gameplay scripters.
Programming languages and scripting systems alike, use one, or sometimes both of two paradigms. These are
- method or function calling based systems.
- message sending based systems.
So what do the two mean? It's actually very simple, but important to know nonetheless.
In a method or function calling system, you have to have to know that an object contains a function in order to use it.
Say you've programmed a dog and that dog has a method that causes it to bark when called. In a calling system you would access the dog, and then call its bark method.
In a message based system you send a message to an object that asks if it knows how to bark, and if it does, then it would execute that code.
The benefit of a message based system is that it allows you to to treat many different objects the same. If two different classes both contain the bark function, even if they're completely different they will respond to that same message.
This is of course possible with function calling through inheritance. If both objects inherit from a base class that defines the bark function, then you can again call the same method on both, you just have to be sure the method exists or you will have an error on your hands.
This is called polymorphism.
There is another advantage to message sending, which is that in many systems you don't actually have to even have a reference to an object you’re trying to send a message to. You can often issue a message globally, and any objects listening for it will pick it up and execute code if they have a corresponding message handler.
So to summarise: Message sending is often more flexible from the offset, but function calling can be slightly more efficient. Realistically these differences are negligible, it's just important to understand the concepts as you might come up against systems that use either one of these in any games you work on.
UE4 for example, implements both in its Blueprints system.