Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: xenogia on Tue 06/04/2010 14:05:45

Title: SOLVED: Walking to char/object in Unhandled_event
Post by: xenogia on Tue 06/04/2010 14:05:45
Just wondering how I would go about making a character move to another character or object in an unhandled event.  I know this automatically done with hotspots as it is an option in General Settings.  But for objects and characters it is a different matter all together.  So how would I go about it?  Here is my unhandled_event code.


function unhandled_event (int what, int type) {

if (what == 1) {
if (type == 1) cEgo.Think ("I can't see anything of importance.");
if (type == 2) cEgo.Think ("There isn't anything I can actually do here.");
if (type == 3) cEgo.Think ("Logically this isn't going to work.");
if (type == 4) cEgo.Think ("I know I'm lonely, but I have no urge to talk at this time.");
if (type == 7) cEgo.Think ("I have no need for this.");
}

if (what == 2) {
if (type == 1) cEgo.Think ("I don't see any point in doing the following action.");
if (type == 2) cEgo.Think ("I have no need to talk to inanimate objects.");
if (type == 3) cEgo.Think ("Logically this isn't going to work.");
if (type == 5) cEgo.Think ("I have no need for this.");
}

if (what == 3) {
if (type == 1) cEgo.Think ("I think I'll ignore them this time round.");
if (type == 2) cEgo.Think ("Not a good idea.");
if (type == 3) cEgo.Think ("I have more use for this item, and I don't have an urge to give it to them.");
if (type == 5) cEgo.Think ("Really I don't think it's a good idea.");
}

if (what == 5) {
if (type == 2) cEgo.Think ("I have no need to talk to inanimate objects.");
if (type == 3) cEgo.Think ("Logically this isn't going to work.");
}

}
Title: Re: Walking to char/object in Unhandled_event
Post by: xenogia on Wed 07/04/2010 00:00:26
No one has any ideas?
Title: Re: Walking to char/object in Unhandled_event
Post by: Crimson Wizard on Wed 07/04/2010 00:36:53
Well, I guess that unhandled even can be caused by mouse-clicking on something?
In which case you can do standart GetAtScreenXY for Hotspot, Object and Character.
Title: Re: Walking to char/object in Unhandled_event
Post by: xenogia on Wed 07/04/2010 00:53:57
Quote from: Crimson Wizard on Wed 07/04/2010 00:36:53
Well, I guess that unhandled even can be caused by mouse-clicking on something?
In which case you can do standart GetAtScreenXY for Hotspot, Object and Character.

Thanks Crimson, but the curious part how would I differentiate between those three scenarios.

Would you give me an example of the line of code?
Title: Re: Walking to char/object in Unhandled_event
Post by: monkey0506 on Wed 07/04/2010 00:56:08
Well the what tells you what was clicked on so you could for example do:

Object *oat = Object.GetAtScreenXY(mouse.x, mouse.y);
if (oat == null) return; // shouldn't happen unless you're manually calling unhandled_event
// otherwise feel free to use oat such as:
player.Walk(oat.X, oat.Y + 10);
Title: Re: Walking to char/object in Unhandled_event
Post by: xenogia on Wed 07/04/2010 01:27:22
I'm guessing you would also add lines of code for Character and Hotspot also?

UPDATE: Played with your code and it works great :)