Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi can you show me how to do it please, im really new to AS3
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
Hi, sorry but can you explain how to implement this..
Copy link to clipboard
Copied
what part of message 6 do you not understand?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now