Relative References
#expandme
Entities
%SELF%
— the entity running the script%PLAYER%
— the player entity
Unlike relative entity names, you can use these two relative entity references everywhere, including the arguments of actions.
%PLAYER%
When used as the target of an action, %PLAYER%
refers to the player entity (the entity marked is_player
on the map in Tiled).
When used in the body of a message (e.g. "Hello, %PLAYER%!"
) it will use the current name of the player entity.
%SELF%
When used as the target of an action, %SELF%
refers to the entity running the script.
When used in the body of a message (e.g. "Hey, there! My name is %SELF%!"
) it will use the current name) of the entity running the script.
Example
#updateme
Let's say we have two entities:
- Bender
- Strong Bad
Plus the %PLAYER%
entity:
- Bob
And the script:
"dialog-introduction": [
{
"alignment": "BOTTOM_LEFT",
"entity": "%SELF%",
"messages": [
"So you're %PLAYER%, huh?\nWell, My name is %SELF%!",
"Got it memorized?"
]
}
]
If the entity Bender ran the script above, you would see the following dialog boxes:
Bender:
So you're Bob, huh?
Well, my name is Bender!
Bender:
Got it memorized?
Because Bender was the entity running the script, the MGE interpreted %SELF%
to be Bender
.
If the same script were run by Strong Bad instead, the %SELF%
reference would be Strong Bad
instead:
Strong Bad:
So you're Bob, huh?
Well, my name is Strong Bad!
Strong Bad:
Got it memorized?
Best Practice: Consistency
All entity references) should be consistent within a dialog, whether they are relative or absolute references. If there are multiple dialogs inside the same script, they should be consistent with each other, as well.
If we change entity
to Bender
instead of %SELF%
, but leave the %SELF%
reference in the dialog messages
alone, the conversation would appear correct if run by Bender, but no one else.
"dialog-introduction": [
{
"alignment": "BOTTOM_LEFT",
"entity": "Bender",
"messages": [
"So you're %PLAYER%, huh?\nWell, My name is %SELF%!",
"Got it memorized?"
]
}
]
If Strong Bad runs the above dialog:
Bender:
So you're Bob, huh?
Well, my name is Strong Bad!
Bender:
Got it memorized?
NOTE: the entity
property is already a relative reference, whereas name
is not. So if Bender's in-game name were changed by the player or a script — let's change it to Flexo for the sake of this example — then the dialog would still appear consistent (as long as Bender was the one running the script):
Flexo:
So you're Bob, huh?
Well, my name is Flexo!
Flexo:
Got it memorized?
However, if you were using name
instead of entity
, then you would begin to have issues even when the correct entity is running the script:
"dialog-introduction": [
{
"alignment": "BOTTOM_LEFT",
"name": "Bender",
"messages": [
"So you're %PLAYER%, huh?\nWell, My name is %Bender%!",
"Got it memorized?"
]
}
]
Bender:
So you're Bob, huh?
Well, my name is Flexo!
Bender:
Got it memorized?
In such a case, you would want to use %Bender%
for name
so that your dialog message and dialog label would be consistent.