S2ENGINE HD
1.4.6
Official manual about S2Engine HD editor and programming
|
In S2Engine every object into the scene or widget of GUI can comunicate with all the other ones through messages. A message has a name and a content. The content format of a message is the following:
where data1, data2, data3, etc.. are the data to send inside the message, their number, their values and their type depends on the message itself, they could be string,integer,floats,vectors depending on the message you want the object must send/receive.
For example the format of a message that contains informations about the 'hit' of the player could be like that:
Messages can be handled and sent by script, othewise objects of certain classes already automatically send/receive messages of various name/format.
There are various types of message an object or widget can send using defined actions:
Every Object/widget receive messages inside the Message() entry point function. To handle a message you must call the ReceivedMessage function inside the Message() entry point. This function has a single param that is the message name, it returns true if the message in input is received. The following is an example of message handling:
That means "If message name is 'hit' then perform some action".
To retreive message data you must use the word 'message' followed by simbol '#' followed by the number of the received message datum, starting from 0: You can use message data as an input param to a function. For example:
In our example ("5.0^Monster"), message#0 is 5.0, message#1 is Monster. You can also know the name of the sender object and use it as an input param of an action. The name of the sender is stored inside a variable which value you can retreive calling the keyword sender. For example:
In this example we write the name of the message sender into the LOG file.
Starting from version 1.03.01 messages can be sent in delayed mode.
S2Engine HD scene editor can send messages to objects. You can tell the editor what messages you want to send to the scripted object, i.e. we say you have exposed (to the editor) the messages. This is very useful to instantly test scripted behaviour of the object when it receive a message. To expose a message you have to use the #message directive at start of your script. In the previous example we have made our object to process the "hit" message, to expose the hit message we write:
So, when inside the editor, we select the scripted object, press "class" tab button to show object class properties and exposed message list, then we can select the message to send and finally press the send... button. If message has some params (the data in the message content) you can insert them, separated by space character, into the params input box showed in figure.