Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: hocuspocus on Wed 07/10/2020 21:54:30

Title: player.changeRoom() Won't Work with Room 35 Specifically
Post by: hocuspocus on Wed 07/10/2020 21:54:30
I'm making a 1st person game, so instead of having to walk to a hotspot/room's edge you just click to go to different rooms via player.ChangeRoom(). I have a hotspot that, when clicked, it goes to room 35. The problem is, the hotspot just does nothing. I tried moving the command to another hotspot, and they also wouldn't work with that command. But when I changed it to room 34, for example, the hotspot would work perfectly fine. And room 35 has already been made and I've worked on it beforehand, so it didn't display any scripting errors or anything.
I don't know why it refuses to go to room 35. I've never had such a problem until now.
Code (ags) Select

function hChemBook_AnyClick()
{
  player.ChangeRoom(35);
}
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Crimson Wizard on Wed 07/10/2020 22:09:11
redacted
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Snarky on Wed 07/10/2020 22:36:40
Just to chime in that I'm fairly sure I've also experienced this same problem, and ended up changing the room number to make the problem go away.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Crimson Wizard on Wed 07/10/2020 23:04:22
I've never heard about this problem before.

Perhaps, try doing "Build->Rebuild all files".

If that does not fix it, maybe if I could have a copy of compiled game I would run it under debugger and see what's going on.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: hocuspocus on Fri 09/10/2020 02:53:34
Sorry for the late respose, but I've figured out the cause.
The hotspot is at the bottom of the screen. I have code in the Global Script where if the mouse is clicking on an edge, then it will proceed to another room based on the current room's custom property:
Code (ags) Select

// called when a mouse button is clicked
function on_mouse_click(MouseButton button) {
 
  if (button != eMouseLeft) return; // do nothing
 
  // clicking on edges code
  if ((mouse.x < 100) && (Room.GetProperty("LeftAble"))) {
    player.ChangeRoom(Room.GetProperty("GoLeft")); // leftmost 100 pixels
  } else if ((mouse.x > 1180) && (Room.GetProperty("RightAble"))) {
    player.ChangeRoom(Room.GetProperty("GoRight"));  // 1280 - 100
  } else if ((mouse.y > 620) && (Room.GetProperty("DownAble")) && (GetLocationType(mouse.x, mouse.y) != eLocationHotspot)) {
    player.ChangeRoom(Room.GetProperty("GoDown"));  // 720 - 100
  }
}


I've already wrote the condition, GetLocationType(mouse.x, mouse.y) == eLocationNothing, to make sure it doesn't ignore any hotspots on the bottom of the screen, but it doesn't seem to work.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Khris on Fri 09/10/2020 07:04:28
Your code says, "only change the room if it isn't a hotspot"...? Which is it?

Also, I can't imagine that whether  hChemBook_AnyClick()  triggers or not is depending on a ChangeRoom parameter.
You can debug stuff like that very easily by inserting a  Display("Room change");
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: hocuspocus on Sat 10/10/2020 06:01:32
For the getLocation condition, I basically meant that if the mouse is hovering over the 100px bottom-most of the screen and it's not hovering over a hotspot, it would move to the next room, so that way if a hotspot is located at the edge of the screen then it wouldn't be ignored because of the edge click code. But it doesn't seem to work.
I wrote the Display("Room change") in the hChem function as you said, and it does actually display it when I click the hotspot, it just doesn't change rooms unless if I click on a part of the hotspot that's not part of the edge (mouse.y < 620).
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Khris on Sun 11/10/2020 20:16:08
Can you double-check that you have entered the correct room number into the custom property?

The only situation in which a player.ChangeRoom command does nothing is when you're sending the player to the room they're already in.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: hocuspocus on Mon 12/10/2020 23:50:02
Yes, I've checked it. And just to be clear, the code that changes room based on custom properties is when you click on a room's edge (it's also in global script), but here the room changes (or it's supposed to) when they click on the hChemBook hotspot. The hotspot doesn't need any custom properties, just ChangeRoom() command. It's just that I suspect that the clicking on edge code is interfering with the hotspot's code, as this particular hotspot is located at the bottom edge of the screen.
Also, I tried putting player.ChangeRoom(35) command in another hotspot that's located at the center of the screen instead of the edge, and it seems to actually work.
Would uploading a screenshot of the room help a bit? I'm still new to AGS and its forums, so I'm not too sure on how to actually do that.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Khris on Tue 13/10/2020 07:41:37
Either  hChemBook_AnyClick()  is called, or it isn't called. The global edge code can only interfere with that, not with a player.ChangeRoom() command inside the function.
(On that note, is that your entire on_mouse_click function?)

You say the Display command you put in there works as expected, so the room change should, too. Just to clarify, you do have something like
Code (ags) Select
function hChemBook_AnyClick()
{
  Display("Going to room 35...");
  player.ChangeRoom(35);
}

right?

If that text appears and the game doesn't change to room 35 after, you've discovered a serious engine bug. The chances of that are very slim. The only other explanation is user error.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: hocuspocus on Tue 13/10/2020 20:33:45
Yes, that's all the code for the on_mouse_click function. There's also similar code in the global repeatedly execute, but it just changes the mouse mode:
Code (ags) Select

// called on every game cycle, except when the game is blocked
function repeatedly_execute() {
  if ((mouse.x < 100) && (Room.GetProperty("LeftAble"))) {
    mouse.SaveCursorUntilItLeaves();
    mouse.Mode = eModeLeft;
  } else if ((mouse.x > 1180) && (Room.GetProperty("RightAble"))) {
    mouse.SaveCursorUntilItLeaves();
    mouse.Mode = eModeRight;
  } else if ((mouse.y > 620) && (Room.GetProperty("DownAble")) && (GetLocationType(mouse.x, mouse.y) != eLocationHotspot)) {
    mouse.SaveCursorUntilItLeaves();
    mouse.Mode = eModeDown;
  } else {mouse.Mode = eModePointer;}

}


That's all I have for this function.

Also here's some of the code for Room 34, which has the hChemBook hotspot:
Code (ags) Select

int getBeaker;

function room_Load()
{
  SetBackgroundFrame(getBeaker);
}


function hTinyBeaker_AnyClick()
{
  //getBeaker = 1;
  //SetBackgroundFrame(getBeaker);
  player.ChangeRoom(35);
  // this ChangeRoom() command is temporarily there for testing purposes. It seems to work
}

function hChemBook_AnyClick()
{
  Display("Room change");
  player.ChangeRoom(35);
}


There's several more hotspot and object functions but they're all currently empty.

Here's a screenshot of Room 34:

(https://i.imgur.com/P7oRbMV.png)

The green hotspot is hChemBook. hTinyBeaker is the little beaker thing between the two giant glass containers.

I also uploaded a video:



Clicking on the hChemBook hotspot doesn't change to the Chemistry Book room, but if I click on the little bookmark as you saw, it still works (I think the bookmark is located above the 100px mark for the edge code, where mouse.y > 620 for 1280x720 dimensions)
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Khris on Tue 13/10/2020 22:37:25
Something very weird is definitely happening there. The fact that the Display message appears but the game doesn't switch rooms is... I don't know.

Also, I'm kinda surprised that your on_mouse_click doesn't prevent interactions; apparently though, Room.ProcessClick() isn't mandatory at all ???

I thought I knew how AGS works. :P
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: hocuspocus on Tue 13/10/2020 22:58:50
Should I send a compiled copy of the game (I don't know how that would work - I'm guessing through email?) I don't know how to fix this issue from coding, but I guess the only way now is to reposition the hotspot and the book's location in the PNG.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: morganw on Tue 13/10/2020 23:45:54
I'm not sure what is going on, but since the room change is queued until the end of script execution potentially there is a chance that some other part of the script is running later and requesting a change back to the current room. If you step through the code with the debugger are there any additional room changes being requested?
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Khris on Wed 14/10/2020 00:20:59
I've also been thinking about two subsequent room changes, however AGS seems to always crash in that case, saying that a NewRoom command is already queued.

Anyway, if we're supposed to take a look at this, we need the source. Zip the entire folder and put it on Dropbox, Google Drive, mediafire, wetransfer, etc.
Send us the link via PM if you don't want other people poking around in it.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Khris on Wed 14/10/2020 08:02:12
Since you're using the BASS template, the proper event to use for clicks on hotspots would've been "interact with hotspot", not "any click on hotspot". Changing that for every hotspot now is tedious and annoying and hopefully not necessary.

Anyway, I've found that it makes a difference where the mouse is located when you click/press a key to dismiss the "Room change" message. If you move the mouse away from the chem book hotspot, AGS changes the room! Only if you leave the mouse where it is does it ignore the command.

At this point I'm considering this an engine bug; the mouse position during a "dismiss display box" click should not have any effect on whether a subsequent ChangeRoom goes through or not.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: hocuspocus on Wed 14/10/2020 19:40:03
Ah, ok. And for the TwoClickHandler script, would it be fine to delete it in the future or would that cause issues, since I'm not really using it? (I'm assuming it's mainly used for left and right mouse click functionality, but I only want to use the right button for my game and no "Look at" modes).
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Crimson Wizard on Sat 17/10/2020 00:31:41
Quote from: Khris on Wed 14/10/2020 08:02:12
Anyway, I've found that it makes a difference where the mouse is located when you click/press a key to dismiss the "Room change" message. If you move the mouse away from the chem book hotspot, AGS changes the room! Only if you leave the mouse where it is does it ignore the command.

At this point I'm considering this an engine bug; the mouse position during a "dismiss display box" click should not have any effect on whether a subsequent ChangeRoom goes through or not.

Sorry, I was away for a while...  Khris, what would be a most basic setup to reproduce this behavior?
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Khris on Sat 17/10/2020 09:51:47
That's a good question, I haven't tried to reproduce it yet, mostly because the game's setup is kind of peculiar :-D
I was also suspecting the room edges to play a part in this, but moving the bottom edge all the way down didn't have any effect.


hocuspocus sent me a Google Drive link, if they're fine with it I'd forward it to you.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: hocuspocus2 on Wed 25/11/2020 00:46:16
Hi, sorry for responding so late, I didn't get notified of any additional replies. I lost my account details after switching to a new laptop so I had to make a new one (hence the different username). I'm ok with others getting the link to the zip file if they want to investigate the issue and take a crack at it. I've stopped sharing it for a while and reshared it just now, I don't know if that changes the old shareable link but if it does I can DM it to you again.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Crimson Wizard on Mon 07/12/2020 09:57:30
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
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: 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?
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: Crimson Wizard on Fri 11/12/2020 07:38:08
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) Select

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.
Title: Re: player.changeRoom() Won't Work with Room 35 Specifically
Post by: hocuspocus2 on Sun 13/12/2020 05:46:09
It worked! I can finally navigate to Room 35 after all this time. Thanks!