SOLVED - Two questions about unhandled_event

Started by sven, Sat 12/08/2006 01:14:07

Previous topic - Next topic

sven

I just set up a very basic unhandled_event function, here's what it looks like:

Code: ags
function unhandled_event(int what, int type) {
  if (gInventory.Visible == true) {
    if (mouse.Mode==4) Display ("That doesn't work.");
    return;
  }
  if (what == 4) {
    character[EGO].Walk(mouse.x+GetViewportX(), mouse.y+GetViewportY(), eNoBlock, eWalkableAreas);
    return;
    }
  if (mouse.Mode==1) character[EGO].Say(String.Format("Ah...%s.", Game.GetLocationName(mouse.x, mouse.y)));
  if (mouse.Mode==2) character[EGO].Say("That's useless.");
  if (mouse.Mode==3) character[EGO].Say(String.Format("Hello, %s. How are you?", Game.GetLocationName(mouse.x, mouse.y)));
  if (mouse.Mode==4) character[EGO].Say("That doesn't work.");
  if (mouse.Mode==5) character[EGO].Say("I am not going to carry that around!");
 }


It works fine (on a very basic, still-needs-lots-of-refinement-level), but there are two things I don't understand:

1. The if (what == 4) is supposed to let the player use any cursor mode for walking somewhere if there's no hotspot or object underneath; however, the character moves in a rather erratic fashion, mostly to some place above and to the left of where I clicked  (at varying distances; sometimes, the character will move just slightly away from where I clicked, sometimes it will move all the way across the screen even thoguh I just clicked a few pixels away from the character). Is there anything about mouse.x and mouse.y I don't  understand?

2. The Game.GetLocationName works fine if there's no walk-to point for the object. As soon as I set a walk-to point, the character will move to the walk-to point, the message is displayed, but the object name is missing (so, instead of "Hello, door. How are you?", it will just say "Hello,. How are you?". After the character has reached the walk-to point, I can click on the object again, and this time, the message is displayed correctly. What am I doing wrong?

As always, thanks in advance for your help.

[addition] Ah, I found the answer to my first question: mouse.x and mouse.y of course just return the screen position, not the room position. Replacing mouse.x with mouse.x+GetViewportX() solved that problem. I'm still stumped on the second one, though...

strazer

2.) Since you coded your GetLocationName function to use mouse coordinates, by the time your character reaches the walk-to point and the function is executed, you probably have moved the mouse somewhere else, hence no name is returned.
If you click when the character is already there, the function is executed immediately, with no chance for you to move the mouse away, hence the name is returned.
The same happens for mouse mode 1, doesn't it?

Anyway, one way to fix it would be by getting the name in the on_mouse_click function, storing it in a global String variable and use that in the unhandled_event function.

sven

Thanks, that worked perfectly...I suspected it had something to do with the delay and movement during walking but couldn't quite get my brain to handle the situation :P

SMF spam blocked by CleanTalk