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

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

Previous topic - Next topic

hocuspocus

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

function hChemBook_AnyClick()
{
  player.ChangeRoom(35);
}

Crimson Wizard

#1
redacted

Snarky

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.

Crimson Wizard

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.

hocuspocus

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

// 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.

Khris

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");

hocuspocus

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).

Khris

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.

hocuspocus

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.

Khris

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
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.

hocuspocus

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

// 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

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:



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)

Khris

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

hocuspocus

#12
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.

morganw

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?

Khris

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.

Khris

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.

hocuspocus

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).

Crimson Wizard

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?

Khris

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.

hocuspocus2

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.

SMF spam blocked by CleanTalk