room transitioning backwards

Started by idkman, Fri 20/10/2017 13:06:44

Previous topic - Next topic

idkman

so walking to the next room work great but going back puts the player at the previous entrance location.
i think its because i set my players location in a room by using:
function room_Load()
{
cplayer.x=23
cplayer.y=260
}
i was thinking of writing something like:
if (cplayer.previousroom == 4)
{
cplayer.x=23;
cplayer.y=260;
}
but it didnt work

NicolaGs

The ChangeRoom function should be able to handle this :

Code: ags
Character.ChangeRoom(int room_number, optional int x, optional int y, optional CharacterDirection direction)


So it's when you exit the previous room that you need to set the player new position:

Code: ags
Character.ChangeRoom(3, 23, 260)
My first game : I Want Out!

idkman

yes but now going to the next room and going back to the previous room will put the player location somewhere else
is there a way to set player location in a room with out using
first load or before and after fade in functions?

Khris

Using player.PreviousRoom should work fine, can you post the ACTUAL code you're using and tell us HOW it failed?

(Using "didn't work" in the tech forums three times will get you banned for life.)

Also, NicolaGs showed you how to fix this issue without using room_Load, but your last reply reads as if you didn't understand or even try ChangeRoom(). When you use player.ChangeRoom(), you obviously need to remove the commands from room_Load, or they will change the position back to the wrong one.

dayowlron

#4
I have used your "PreviousRoom" idea a lot and that seems to work fine for me. Do you mean from the first room they move to a second room, move around then when they go back to the first room they are at the same location they were in the second room?
You said "PreviousRoom" doesn't work. Why not? did you have the correct room number?
why do you not want to use the before or after fade functions?
I believe the problem is the room is loaded only once and since you have been to the room before it is not executing the room_Load function again(just a thought). that is what the BeforeFadeIn function is used for. Put your Previous room code in the before fade event and I believe that should work correctly.
Using the ChangeRoom call is the preferred way though.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

idkman

Quote from: dayowlron on Fri 20/10/2017 15:01:45
I have used your "PreviousRoom" idea a lot and that seems to work fine for me. Do you mean from the first room they move to a second room, move around then when they go back to the first room they are at the same location they were in the second room?
the previous room code that i wrote was incorrect.
it says: errir (line 35) previousroom is not a public member of charecter.
also using the first time load function with the player.x/y wont fix it because for a second the charecter is not in the correct spot and it does not display text like in the code, so i am forced to
write the previousroom script how ever it gets an error

Khris

AGS autocompletes your code. Unless you deliberately mistype and ignore the window, AGS will suggest PreviousRoom, after you've typed "player" followed by a dot and a p.
Capitalization is important.

Quote from: dayowlron on Fri 20/10/2017 15:01:45I believe the problem is the room is loaded only once and since you have been to the room before it is not executing the room_Load function again(just a thought). that is what the BeforeFadeIn function is used for. Put your Previous room code in the before fade event and I believe that should work correctly.
The "enter room before fadein" event by default creates the room_Load function, which is consequently run every time the room is entered. You're thinking about "room_FirstLoad".


Now, to hopefully put this to bed: ONLY use
Code: ags
  // in room 4, when walking on region / interacting with door / etc.
  player.ChangeRoom(3, 23, 260, eDirectonRight);


AND REMOVE all player positioning code from room_Load and room_AfterFadein and room_FirstLoad and whatever else you tried. You do not need anything else.
Please try and get this right, because I'm starting to pull my hair out, given how we've turned an exceptionally basic non-problem into a huge issue with loads of people talking past each other.

SMF spam blocked by CleanTalk