Room transition / Entering from off screen issue [SOLVED]

Started by CCrane, Tue 15/11/2022 12:04:55

Previous topic - Next topic

CCrane

Hi,

I'm sorry if this has been dealt with elsewhere but I haven't found it. So what I want is my character to walk some steps off a walkable area and disappear behind a walk-behind/off-screen before room transition and the opposite to happen when the character emerges in the other room.

That's the code I used. (Taken from Ensminger and Madi's "Game Design with AGS", btw.)

In room 2
Code: ags
function hHallway_AnyClick()
{
  if (Verbs.UsedAction(eGA_WalkTo)) {
    player.Walk(100, player.y, eBlock, eAnywhere);
    player.ChangeRoom(1, 630, 255, eDirectionLeft);
  }

This first part works nicely - as things in room 2 are concerned - but what doesn't is this:

In room 1
Code: ags
function room_AfterFadeIn()
{
  if (player.PreviousRoom == 2) {
    player.Walk(551, 255, eBlock, eAnywhere);
  }
}

More specifically, it does work but the character appears way below the changeRoom-coordinates mentioned in the hHallway function (in fact, exactly on the edge of the room's walkable area) and then walks diagonally up to the coordinates given in the second function. Frankly, I don't know which of those functions gives me trouble but it seems to me the eAnywhere parameter isn't recognized properly. It's supposed to overrule walkable areas, no?

Any help is appreciated


P.S. I'm using AGS 3.5.1 on Linux (tumbleweed template)

@ChristophCrane_ (Indie author)

Matti

#1
Not sure why the coordinates are wrong. Do you by any chance set the player's (y)coordinates somewhere in room 1 (in room_Load for example)?

What you could do is this:

Code: ags
function room_AfterFadeIn()
{
  if (player.PreviousRoom == 2) {
    player.y = 255;
    player.Walk(551, 255, eBlock, eAnywhere);
  }
}

Or put

Code: ags
if (player.PreviousRoom == 2) player.y = 255;

in room_Load().


EDIT:
Quote from: CCrane on Tue 15/11/2022 12:04:55I don't know which of those functions gives me trouble but it seems to me the eAnywhere parameter isn't recognized properly. It's supposed to overrule walkable areas, no?

The eAnywhere parameter doesn't matter here, if the player is walking correctly. If something is not working properly in this code it's the player.ChangeRoom command.

Khris

Open GlobalScript.asc and navigate to the on_event function. In there you will find:
Code: ags
  if (event==eEventEnterRoomBeforeFadein || event==eEventRestoreGame)
    player.PlaceOnWalkableArea();
This is what screws things up for you, simply remove these two lines altogether.

CCrane

I was a bit reluctant to change GlobalScript.asc at first so I tried Mattis solution first but it worked only partially (i.e. the character still appeared on the wrong place initially on the walkable area and only then was moved immediately to the right place.)
Khris' solution worked, however.

Thanks so much both of you / Danke euch

@ChristophCrane_ (Indie author)

Snarky

Quote from: CCrane on Tue 15/11/2022 15:55:26I was a bit reluctant to change GlobalScript.asc at first

As you proceed to make your game, you will have to change GlobalScript. That's where a lot of the game code goes. (I do understand the caution about editing the bits that come pre-written as part of the template, though.)

Khris

Indeed, I originally wanted you to send you to the line number but didn't because the GlobalScript is heavily edited and added to during development.

Anyway, these two lines put the player on a walkable area as the method name suggests, in this case immediately after changing the room or loading the game. The latter seems a bit weird but the former certainly makes sense, unless of course you want the player to visibly walk into the room from beyond the edge.

In general it's a good thing to be wary of editing code you don't understand but this is really a design choice and should not be part of the template imo.

CCrane

Quote from: Snarky on Tue 15/11/2022 16:52:05As you proceed to make your game, you will have to change GlobalScript.
Thanks for the advice and encouragement, guys. I have no coding background whatsoever and understand barely anything of the more advanced functions in GlobalScript (or elsewhere for that matter  :-D ) so I'm always fearful of breaking something. I've set up a pseudo script in AGS to keep track of my changes, however.

Quote from: Khris on Tue 15/11/2022 17:02:11Indeed, I originally wanted you to send you to the line number but didn't because the GlobalScript is heavily edited and added to during development.
I had a look at the sources of some games and I noticed that some even have only a single script, i.e. GlobalScript, that includes anything. The search function is a real live saver, though. Thanks again.

Quote from: Khris on Tue 15/11/2022 17:02:11[...] but this is really a design choice
It's just a pity that it kind of breaks eAnywhere under some - admittedly - special circumstances.


@ChristophCrane_ (Indie author)

SMF spam blocked by CleanTalk