Room on_mouse_click not claiming event? (SOLVED)

Started by Rui 'Trovatore' Pires, Mon 05/02/2007 13:59:26

Previous topic - Next topic

Rui 'Trovatore' Pires

Ok, so I have it set up this way: there's ways of checking where the mouse cursor is and displaying the navigational arrows accordingly (left, right, forward, turn around, etc). The code for actually moving is in the global on_mouse_click:

Code: ags
if (button == eMouseLeft) {
    //NAVIGATION
    if (mouse.Mode==eModeTurnArou) player.ChangeRoom(GetRoomProperty("TurnAround"));
    else if (mouse.Mode==eModeRight) player.ChangeRoom(GetRoomProperty("Right"));
    else if (mouse.Mode==eModeLeft) player.ChangeRoom(GetRoomProperty("Left"));
    else if (mouse.Mode==eModeUp) player.ChangeRoom(GetRoomProperty("Up"));
    else if (mouse.Mode==eModeDown) player.ChangeRoom(GetRoomProperty("Down"));
    else if (mouse.Mode==eModeUseinv) { //USEINV
      if (Hotspot.GetAtScreenXY(mouse.x, mouse.y)==hotspot[0] && Object.GetAtScreenXY(mouse.x, mouse.y)==null && Character.GetAtScreenXY(mouse.x, mouse.y)==null && InventoryItem.GetAtScreenXY(mouse.x, mouse.y)==null) {
        player.ActiveInventory.Graphic--;
        player.ActiveInventory=null;
        mouse.Mode=eModeDefault;
      }
			else ProcessClick(mouse.x, mouse.y, eModeUseinv);
    }
    
    else ProcessClick(mouse.x,mouse.y, mouse.Mode);
    }


Now, there's a room in which I want the character to go back to the room he was previously in. So I thought I'd do this in the room script:

Code: ags
function on_mouse_click(MouseButton button) {
//  if (mouse.Mode==eModeTurnArou) {
    AbortGame("");
    player.ChangeRoom(player.PreviousRoom);
    ClaimEvent();
//  }
}


The comments are there because, as the code didn't work, I tried removing that check. The AbortGame was added to see if the game was actually calling this function. It's not, the game does not abort. What happens is that the global on_mouse_click is called *first*. This isn't the way it's supposed to happen, is it? After all,

QuoteThe normal order in which scripts are called for on_key_press and on_mouse_click is as follows:

room script
script modules, in order
global script

So basically, I'd like to know why this is happening, what is it that I've missed... it looks right, doesn't it? But it's certainly not acting right. Any help and/or opinions appreciated.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gilbert

Odd, your codes worked for me.
I just started a new game and copied your room on_mouse_click() codes to a new room and start in that room.
just clicking anywhere correctly display the "error" in AbortGame(), commenting out the AbortGame() lineproduced an error saying it couldn't return to room -1 (which is correct behaviour).

Try to look at the codes around the function codes in the room script,maybe there're something wrong before or after the function which caused your problems.

Khris

Same here.
I know it sounds a bit silly, but you could try moving the room's on_mouse_click to the top of the room script.

Rui 'Trovatore' Pires

#3
It is already at the top. Hmmm, I'll check for anything overly silly I might have done.

EDIT - No go... I really don't think I'll figure it out by myself, because as far as I can see, there is nothing wrong - therefore it's something I'm overlooking, therefore it's something I won't spot.

What really bugs me is that, really, theoretically that code should work no matter what. I'm using a ClaimEvent inside an on_mouse_click on the room script and I don't even check for buttons, or mode, or anything. How can it possibly not trigger? What could possibly be interfering?

Oh, hang on...

I just remember that all of this happens through a clickable GUI, so in fact the clicks are processed through the GUI. Can that be related?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Scorpiorus

Quote from: Rui "Trovatore" Pires on Tue 06/02/2007 00:14:09I just remember that all of this happens through a clickable GUI, so in fact the clicks are processed through the GUI. Can that be related?

Yep, on_mouse_click() is not invoked on clicking over a clickable GUI, you then need to use on_event() instead :)

Rui 'Trovatore' Pires

Heh. So silly, how you forget these things. Thanks a bunch. :)
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gilbert

Alternately, you may also check with Mouse.IsButtonDown(eMouseLeft) in repeatedly_execute[_always]() .


Rui 'Trovatore' Pires

Oh, there's many ways I can do it, now that I know what's wrong. I think I'll just add a little if to the already shown navigational code, and maybe an extra boolean property - if the room has property GOBACK and the mode is TURNAROUND then player.ChangeRoom(player.PreviousRoom). Thanks again!
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

monkey0506

I'm not 100% sure, but I would imagine you can even script an interface_click into your room's scripts (as you can do it with modules).

Scorpiorus

Room script only supports the following global event handling functions being independent of the Interaction Editor at the moment:

repeatedly_execute_always
on_key_press
on_mouse_click


Module script supports:

game_start
repeatedly_execute
repeatedly_execute_always
on_event
on_key_press
on_mouse_click


But of course, you can cook up something like this:

Module script
Code: ags
function interface_click( int interface, int button )
{

}


function on_event( EventType event, int data )
{
Ã,  Ã,  if (event == eEventGUIMouseUp)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  int theGUI = data;
Ã,  Ã,  Ã,  Ã,  GUIControl *control = GUIControl.GetAtScreenXY( mouse.x, mouse.y );
		
Ã,  Ã,  Ã,  Ã,  if (control != null) interface_click( theGUI, control.ID );
    }
}

monkey0506

Okay. Once again laziness doesn't pay off in not actually looking it up. Thanks Scorpiorus. :)

SMF spam blocked by CleanTalk