Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trying to make an NPC like..

New Here ,
Jan 23, 2013 Jan 23, 2013

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.

TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 23, 2013 Jan 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.

Translate
Community Expert ,
Jan 23, 2013 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 23, 2013 Jan 23, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2013 Jan 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 23, 2013 Jan 23, 2013

Yes, the npc is movie clip and yep i am doing a hittesting when character collide with it then thats the only time you can talk to the NPC. And yes if you meant like the text should be just right or on the top of the NPC.

I was planning to put at least 1 or 2 NPC as I am only doing 1 level for the meantime.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2013 Jan 23, 2013

you could use something like:

npc1.phraseCount=0;

npc1.phraseA = ['this is the first phrase','this is 2nd', '3rd','4th and last phrase. npc1 will start repeating after this'];

if(player is near npc1 and talk key pressed){

doorNote.text=npc1.phraseA[npc1.phraseCount];

npc1.phraseCount=(npc1.phraseCount+1)%npc1.phraseA.length;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 23, 2013 Jan 23, 2013

Hi, sorry but can you explain how to implement this..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2013 Jan 23, 2013
LATEST

what part of message 6 do you not understand?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 23, 2013 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines