Be a Supporter!

Interactive AI

  • 367 Views
  • 8 Replies
New Topic Respond to this Topic
Underdawg253
Underdawg253
  • Member since: Oct. 6, 2006
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Interactive AI 2008-09-23 16:42:05 Reply

Hello! Well, I'm working on a RPG-type game and can't seem to find what I'm looking for on this subject(though I'm not really sure what I AM looking for). I've checked through the AS: Main and such, maybe I missed it, but:

I want to have the player speak and interact with NPCs. I wasn't sure if there was a technical term for it or anything, but regardless I can't seem to find anything on the subject...Any help would be greatly appreciated!

uyersuyer
uyersuyer
  • Member since: May. 15, 2002
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Interactive AI 2008-09-23 17:20:12 Reply

Make sure the player has an instance name of 'player, then make the NPC a movieclip, then put this code on it:

onClipEvent(enterFrame) {
	if (Key.isDown(Key.SPACE)){
		if(hitTest(player)){
			gotoAndStop(2);
		}
	}
}

That'll make the NPC movieclip go to its second frame if the player presses space next to it, so have some text on that frame. From there, it should be pretty easy to add code to make it go back to its original frame by pressing space or any other key you want. Might not be the most efficient way, but I'm in a hurry and it's the easiest I could think of. I didn't test it out, so I'm not 100% on it either.


"Whoever said 'winners never quit' obviously never considered addicts." - Hoeloe

BBS Signature
Underdawg253
Underdawg253
  • Member since: Oct. 6, 2006
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Interactive AI 2008-09-23 18:44:53 Reply

That'll make the NPC movieclip go to its second frame if the player presses space next to it, so have some text on that frame. From there, it should be pretty easy to add code to make it go back to its original frame by pressing space or any other key you want. Might not be the most efficient way, but I'm in a hurry and it's the easiest I could think of. I didn't test it out, so I'm not 100% on it either.

I'll test this tonight, thanks!

Underdawg253
Underdawg253
  • Member since: Oct. 6, 2006
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Interactive AI 2008-09-24 16:02:24 Reply

I know this is a double-post and a bump, but the code given works partially. It does go to the second frame, but not when I push SPACE. It does it automatically. I've tried stop(); actions and such but it doesn't seem to be helping the situation.

Any more elaboration on the previous code would be awesome.

TheFunkyMunk
TheFunkyMunk
  • Member since: Dec. 8, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to Interactive AI 2008-09-24 16:28:06 Reply

Try using Keyboard Events instead of EnterFrame. I don't know if their in AS2 or not though. I use AS3.


BAH! 3.141592653589793238462643383279502 8841971693993751058209749445920...

Underdawg253
Underdawg253
  • Member since: Oct. 6, 2006
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Interactive AI 2008-09-24 16:54:08 Reply

I'm using AS2, but I've never heard of those commands before.

Underdawg253
Underdawg253
  • Member since: Oct. 6, 2006
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Interactive AI 2008-09-25 16:11:59 Reply

Bumping and double-posting isn't fun. Someone PLEASE help correct this code!

TheFunkyMunk
TheFunkyMunk
  • Member since: Dec. 8, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to Interactive AI 2008-09-25 16:19:59 Reply

events are done like this.

addEventListener(EVENT.ENTERFRAME, myFunc);
function myFunc(e:Event) {
// Stuff
}


BAH! 3.141592653589793238462643383279502 8841971693993751058209749445920...

Underdawg253
Underdawg253
  • Member since: Oct. 6, 2006
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Interactive AI 2008-09-25 16:32:36 Reply

At 9/25/08 04:19 PM, TheFunkyMunk wrote: events are done like this.

addEventListener(EVENT.ENTERFRAME, myFunc);
function myFunc(e:Event) {
// Stuff
}

I'm pretty bad at Actionscript so I have no idea what most of that means. I'm decent with Flash itself but when it comes to scripting, I'm terrible.