Well here's a structure you may want to try using to code NPCs on a KeyDown Event located in the text actor:
- Code: Select all
if (distance(player.x, player.y, NPC.x, NPC.y) <= 20) //Event only occurs when player is close enough to NPC (Defines a 20 px radius).
{
EventDisable("player", EVENTALL); //Disable player controls
transp = 0; //Set the Messages to be visible
switch(Dialogue_Position) //Keeps the position in the dialogue
{
case 1: sprintf(text,"Hello Link, how are you today?",text); //Change the message
Dialogue_Position++; //Increment Dialogue's position by 1
break; //Ignore the rest of "case" labels
case 2: sprintf(text,"Have you visited the BAKERY yet?",text); //Same as Case 1 (You can have as many as you wish)
Dialogue_Position++;
break;
case 3: sprintf(text," ",text);
transp = 1; //Make the messages invisible.
EventEnable("player", EVENTALL); //Enable player controls
Dialogue_Position = 0; //Reset Dialogue Position to 0 in order to be able to go through the dialogue another time
break;
}
}
Note that it would be in your best interest to set your NPCs in a manner to avoid convergence of the proximity radii in order to avoid unexpected (and funky) behavior when initiating the preset conversations. Also try keeping the scripts as organized as possible so you can easily modify your text.
You will probably need to use the "\n" control character in your text formatting in order to split your text onto other lines (Like using ENTER).
Example:
- Code: Select all
sprintf(text,"This example text string\nis spread over two lines!!!",text);
Hopefully this helps you in your game's conception. If you have any other questions about this, ask!
Well, that's all for now!
-- Pyrometal --