player.changeRoom() Won't Work with Room 35 Specifically

Started by hocuspocus, Wed 07/10/2020 21:54:30

Previous topic - Next topic

Crimson Wizard

#20
Ok, so, I did some research on the game files, and this is what I found.

Short version:
The room does change to 35, but then it changes back to 34. This happens before room 35 can be drawn on screen even once, this is why it just looks like change room did not work...
(you can kind of guess what happens if you set room transition to "Fade-in/out" instead of "Instant")
This happens because on_mouse_click in TwoClickHandler is called while it is room 34, but on_mouse_click in global script afterwards is called when the room is already 35, and it detects click on the "bottom edge", which returns room back.


Long technical version:
Mouse click event fires.
Mouse event is first handled by TwoClickHandler's on_mouse_click. It starts hotspot interaction, and ChangeRoom is scheduled.
As script ends, the scheduled ChangeRoom is executed, even though the mouse event is not completed by all scripts yet.
New room 35 loads, but it is not displayed yet.
Engine gets back to handling mouse events, and because it was not Claimed by TwoClickHandler, it passes it further into GlobalScript's on_mouse_click.
So, GlobalScript's on_mouse_click gets called already in room 35, and it happens to call ChangeRoom for the second time, returning you back to room 34.


Now... erm... considering all the circumstances, this "split" mouse click handling is probably a pretty common (but unknown) thing in AGS games, its just that not all games have full combination of factors to cause a problem. It's not too common to have several on_mouse_click() in script modules that would all handling clicks on room, and ChangeRoom right in on_mouse_click.


The way to fix this in game is, perhaps, adding ClaimEvent() call in TwoClickHandler right after it calls ProcessClick.



EDIT: Opened bug ticket: https://github.com/adventuregamestudio/ags/issues/1144

hocuspocus2

Ok, thank you for investigating this. I did try to add ClaimEvent() after every Room.ProcessClick line, but it seems to interfere with the edges code on the on_mouse_click function and it didn't work, so I couldn't navigate to Room 35 initially.
So I changed the player's starting room to 34, and the hotspot that leads to Room 35 does work. Maybe I should modify the edges code?

Crimson Wizard

Quote from: hocuspocus2 on Fri 11/12/2020 02:09:51
Ok, thank you for investigating this. I did try to add ClaimEvent() after every Room.ProcessClick line, but it seems to interfere with the edges code on the on_mouse_click function and it didn't work, so I couldn't navigate to Room 35 initially.
So I changed the player's starting room to 34, and the hotspot that leads to Room 35 does work. Maybe I should modify the edges code?

I think the problem is that TwoClickHandler does not check if there's anything under mouse. ProcessClick also does not return any result, so you cannot tell whether there was anything or not.

I guess as a quick fix you could wrap every Room.ProcessClick into something like:
Code: ags

if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
{
     Room.ProcessClick(... same params as before ...);
     ClaimEvent();
}


The ProcessClick and ClaimEvent will be only called if there's a hotspot or object under the mouse, and your edge code might work again.

hocuspocus2

It worked! I can finally navigate to Room 35 after all this time. Thanks!

SMF spam blocked by CleanTalk