Jibble

Author Topic: player.changeRoom() Won't Work with Room 35 Specifically  (Read 584 times)

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: Adventure Game Studio
  1. function hChemBook_AnyClick()
  2. {
  3.   player.ChangeRoom(35);
  4. }
  5.  

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #1 on: 07 Oct 2020, 22:09 »
redacted
« Last Edit: 07 Oct 2020, 23:02 by Crimson Wizard »

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #2 on: 07 Oct 2020, 22:36 »
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.

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #3 on: 07 Oct 2020, 23:04 »
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.

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #4 on: 09 Oct 2020, 02:53 »
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: Adventure Game Studio
  1. // called when a mouse button is clicked
  2. function on_mouse_click(MouseButton button) {
  3.  
  4.   if (button != eMouseLeft) return; // do nothing
  5.  
  6.   // clicking on edges code
  7.   if ((mouse.x < 100) && (Room.GetProperty("LeftAble"))) {
  8.     player.ChangeRoom(Room.GetProperty("GoLeft")); // leftmost 100 pixels
  9.   } else if ((mouse.x > 1180) && (Room.GetProperty("RightAble"))) {
  10.     player.ChangeRoom(Room.GetProperty("GoRight"));  // 1280 - 100
  11.   } else if ((mouse.y > 620) && (Room.GetProperty("DownAble")) && (GetLocationType(mouse.x, mouse.y) != eLocationHotspot)) {
  12.     player.ChangeRoom(Room.GetProperty("GoDown"));  // 720 - 100
  13.   }
  14. }
  15.  

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.

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #5 on: 09 Oct 2020, 07:04 »
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");
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #6 on: 10 Oct 2020, 06:01 »
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).

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #7 on: 11 Oct 2020, 20:16 »
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.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #8 on: 12 Oct 2020, 23:50 »
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.

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #9 on: 13 Oct 2020, 07:41 »
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: Adventure Game Studio
  1. function hChemBook_AnyClick()
  2. {
  3.   Display("Going to room 35...");
  4.   player.ChangeRoom(35);
  5. }
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.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #10 on: 13 Oct 2020, 20:33 »
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: Adventure Game Studio
  1. // called on every game cycle, except when the game is blocked
  2. function repeatedly_execute() {
  3.   if ((mouse.x < 100) && (Room.GetProperty("LeftAble"))) {
  4.     mouse.SaveCursorUntilItLeaves();
  5.     mouse.Mode = eModeLeft;
  6.   } else if ((mouse.x > 1180) && (Room.GetProperty("RightAble"))) {
  7.     mouse.SaveCursorUntilItLeaves();
  8.     mouse.Mode = eModeRight;
  9.   } else if ((mouse.y > 620) && (Room.GetProperty("DownAble")) && (GetLocationType(mouse.x, mouse.y) != eLocationHotspot)) {
  10.     mouse.SaveCursorUntilItLeaves();
  11.     mouse.Mode = eModeDown;
  12.   } else {mouse.Mode = eModePointer;}
  13.  
  14. }
  15.  

That's all I have for this function.

Also here's some of the code for Room 34, which has the hChemBook hotspot:
Code: Adventure Game Studio
  1. int getBeaker;
  2.  
  3. function room_Load()
  4. {
  5.   SetBackgroundFrame(getBeaker);
  6. }
  7.  
  8.  
  9. function hTinyBeaker_AnyClick()
  10. {
  11.   //getBeaker = 1;
  12.   //SetBackgroundFrame(getBeaker);
  13.   player.ChangeRoom(35);
  14.   // this ChangeRoom() command is temporarily there for testing purposes. It seems to work
  15. }
  16.  
  17. function hChemBook_AnyClick()
  18. {
  19.   Display("Room change");
  20.   player.ChangeRoom(35);
  21. }
  22.  

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

Here's a screenshot of Room 34:



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)

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #11 on: 13 Oct 2020, 22:37 »
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
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #12 on: 13 Oct 2020, 22:58 »
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.
« Last Edit: 13 Oct 2020, 23:20 by hocuspocus »

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #13 on: 13 Oct 2020, 23:45 »
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?

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #14 on: 14 Oct 2020, 00:20 »
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.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #15 on: 14 Oct 2020, 08:02 »
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.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #16 on: 14 Oct 2020, 19:40 »
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).

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #17 on: 17 Oct 2020, 00:31 »
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?

Re: player.changeRoom() Won't Work with Room 35 Specifically
« Reply #18 on: 17 Oct 2020, 09:51 »
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.
Fail at Floaty Rog' now!  still having to deal with what games are going through