Typically messages are of two types; global and local. In either case they are handled in the same manor with the only difference being that the local messages require a local message stack that is not visible to the outside world to be in place while the global ones are all held in a single stack that anyone can view.
The problem that you describe, moving along a set path over a given time, really isn't something that you would implement using a message system. Instead it requires a State Machine or process script that "tells the actor what to do" and "says what the actor is currently doing".
I'll try to cover both topics here for a minute, but know there are 1000's of articles on this and a bit of time with google would be your best bet.
At the basic level a message stack is a FIFO (first in first out) stack that has the ability to push a message onto the bottom and pop a message from the top. This allows messages to be processed in the order that they were presented to the target (typically called an actor).
Basic psudo code for the stack:
Code:
AStack = object
Items = collection
method Push(What)
id = Items.Count
Items.Count++
Items[id] = What
end Push
method Pop() -> Top
if Items.Count > 0 then
return Items[0]
Items.Remove(0)
else
return nil
end
end Pop
end
Now, you could give priority and timing to messages (such as windows and some games do) but this is really a waste of processing time since you have to iterate the stack looking for the next valid message.
Instead you setup a state machine that knows what to do and when. You build a state machine by building rules and then implementing those rules in code.
Here is an example set of rules to make an actor move in a rectangle:
If the actor is at 0, 0 then walk right to 10, 0
If the actor is at 10, 0 then walk down to 10, 10
If the actor is at 10, 10 then walk left to 0, 10
If the actor is at 0, 10 then walk up to 0, 0
This would be a very bad thing to use exactly, but its a good example. Remember that your rules should take into account the unexpected happening (in our example above the actor manages to walk to 11, 10 before the next process loop).
Here is psudo code again:
Code:
case Actor.Position of
0, 0 : Stop; Start Walk Right
10, 0 : Stop; Start Walk Down
10, 10 : Stop; Start Walk Left
0, 10 : Stop; Start Walk up
else
Continue Walk
end
I hope that gives you a very basic starting point and at least gives you some good search terms for google .
Bookmarks