Skip to main content
Known Participant
January 23, 2013
Answered

Trying to make an NPC like..

  • January 23, 2013
  • 2 replies
  • 1337 views

Hello everyone I'm trying to make an NPC like system that talks to the player when the player press a key, I sort of know how to make a pop-up text appear when a key is pressed, but I want to make it like a dialog like so the NPC is like talking to the player to give a quest or information.

var textIsShowing:Boolean = false;

var buttonPressedOnce = false;

if(talkKeyDown == true){

if (textIsShowing == false && buttonPressedOnce== false){

if(charMC.hitTestObject(back.other.doorLvl)){

doorNote.text = "Door is locked!";

textIsShowing = true;

}

} else if (textIsShowing==true && buttonPressedOnce==true) {

doorNote.text = "";

textIsShowing = false;

}

} else {

if (textIsShowing == true && buttonPressedOnce== false ){

buttonPressedOnce = true;

} else if (textIsShowing == false && buttonPressedOnce == true){

buttonPressedOnce = false;

}

}

How can I put another text message when I press the same key, I'm trying to have an NPC like so when the character talks to the npc it shows a dialog text.

Press key "then shows the first line of text"

Press again "shows another text" ....

until it disappear/closes when the dialog has finished.

This topic has been closed for replies.
Correct answer Ned Murphy

Use an array holding the text phases and a counter variable such that each key press shows the current text pointed to by the index and then increments that index.

2 replies

Ned Murphy
Ned MurphyCorrect answer
Brainiac
January 23, 2013

Use an array holding the text phases and a counter variable such that each key press shows the current text pointed to by the index and then increments that index.

kglad
Adobe Expert
January 23, 2013

use a counter to track how many times the talk key is pressed during the encounter and use that counter to determine which text to display.

aganuzAuthor
Known Participant
January 23, 2013

Hi can you show me how to do it please, im really new to AS3

kglad
Adobe Expert
January 23, 2013

each npc should have its own counter and phrases.  you'll also need to determine which npc should talk when the talk key is pressed.  that's normally done by proximity or hittesting with the player character.

assuming your npc is a movieclip, you can assign the counter and phrases directly.  but from your setup it may be the case that the phrases used by the npc depend on the npc's location.  is that true?