(Solved)Changeroom x,y coords

Started by Construed, Tue 19/11/2013 00:55:13

Previous topic - Next topic

Construed

Hi, I'm using hotspots like

Code: ags

function hHotspot1_WalkOn()
{
   
player.ChangeRoom(4, 50, 151);

  

}


And i was wondering if there's something I could attach to this function that would cause the player to enter the next room relative to where he exited the last, say the player exits the upper right side of the room i would like him to enter the upper left side of the next room instead of entering at a pre-determined location.
Although It would have to be able to detect non-walkable areas so the player doesn't get stuck.
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Andail

I don't really understand how that hotspot works. Do you mean you have one hotspot in each corner/edge of the room, and you want to teleport accordingly? Because if nothing else is specified, that should already happen (just write the room number and skip the coordinates). Alternatively, you store the player's coordinates as variables, and insert them into the ChangeRoom instead of numbers.

There's a function that will place the character on the nearest walkable area. Can't remember exactly what it's called from the top of my head, but it should be easy to find in the manual.

monkey0506

Andail, IIRC ChangeRoom without the coordinates specified will move the character to the new room at the same coordinates. I believe that what Construed is looking for is actually the ChangeRoomAutoPosition function:

Quote from: The ManualCharacter.ChangeRoomAutoPosition(int room_number, optional int newPosition)

Changes the room that the character is in, and positions him along one of the room edges.
This command simulates the behaviour of the old "Go to room" interaction command from AGS 2.72 and previous versions. If newPosition is not specified or is 0, the character will be placed on the opposite side of the new room, if he is within 10 pixels of a room edge in the current room.

Altenatively, you can specify the position where he will get placed in the new room. newPosition can be 1000 for the left edge, 2000 for the right edge, 3000 for the bottom edge and 4000 for the top edge. Then, add on the offset within that edge where you want to place the character, in normal room co-ordinates.

Construed

There are 4 hotspots in each room leading left/right/up/down.

This is what I'm trying to accomplish:

The player leaves the room at this location.


But when he enters the next room it is not relative to where he left as the circle shows.


I need it to place him at the same x coordinate or the same y coordinate depending whether he goes up/down or left/right

That way if he is say, following the rocks along the bottom of the screen, it wont place him towards the middle, but at the same coordinate as he was in the last room.

I tried removing the x,y coords from the changeroom function and It didn't do it.

That ChangeRoomAutoPosition doesn't seem like it does that unless I'm incorrect?
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

monkey0506

#4
I'm actually more confused now about what you do want. ChangeRoomAutoPosition is designed so that if the player exits screen left, they will enter screen right by default - or you can specify what side of the room you want them to enter from. AFAIK this doesn't change the player's other coordinate (in this case, the y coord) unless you've specified the newPosition parameter, in which case you could simply add the current value as the offset:

Code: ags
function hLeftExit_WalkOn()
{
  player.ChangeRoomAutoPosition(4); // change to room 4: x will be room's right edge, y will stay the same (AFAIK)
  // ALTERNATELY:
  // player.ChangeRoomAutoPosition(4, 2000 + player.y); // change to room 4: x will be room's right edge, y will definitely stay the same
}


If that's not what you're wanting, then I'm confused.




If you don't want to rely on the room edges (as defined in the editor), then you could still use coordinates and just pass the current opposing coord into ChangeRoom (like Andail said):

Code: ags
function hLeftExit_WalkOn()
{
  player.ChangeRoom(4, Room.Width - 10, player.y); // assumes rooms are same width, preserves player's y
}

Construed

Hmm, nothing seems to work but I greatly appreciate you guys trying!
I guess theirs a communications barrier here :(
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

selmiak

player.ChangeRoomAutoPosition() reads in the manual like exactly what you are describing?!

festilligambe

I think what he's looking for in that example is that if the player leaves the screen on the left side he'll move to a new room and come out on the right side so his x value will change but he will be the same distance from the bottom of the screen so his Y value will remain constant. But he's using a hotspot also when I think room edges would work better.
New to programing, old school to adventure games

Construed

I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

monkey0506

...that's what ChangeRoomAutoPosition is for... ???

Construed

Ah, well i tried it but It didn't work, it just placed the character in the middle..
I thank you for taking the time to explain it and i guess im just going to mess with it till i figure it out.

Sorry for the lack of understanding, I know its hard to talk to a retarded block of wood T.T
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Khris

How exactly did you try it? Could you post the code?
It only works with just the new room as parameter if at the time it is called, the player is within 10 pixels of the room edge.

Construed

Code: ags

function hHotspot2_WalkOn()
{
player.ChangeRoom(34, 45, 110); //original code which i commented to test out the code below.
player.ChangeRoomAutoPosition(34, 2000 + player.y);
}


The hotspot is most likely more than 10 pixels from the edge so that may be the problem?
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

selmiak

try
Code: ags
function hHotspot2_WalkOn()
    {
//    player.ChangeRoom(34, 45, 110); //original code which i commented to test out the code below.
    player.ChangeRoomAutoPosition(34);
    }
     

Construed

Ah it seems to work now, but I had to move the hotspot in the next room, it was auto landing on it which might have been the problem with some of the other code.

However removing the hotspot from the next room would make it impossible to go back to the previous room so how can I make it where the player won't land on the hotspot?

I think it would be the same with edges wouldn't it?
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

Nevermind, somehow it seems to work with edges reguardless, Thanks everyone for the help!
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

monkey0506

Quote from: Khris on Wed 20/11/2013 01:01:06It only works with just the new room as parameter if at the time it is called, the player is within 10 pixels of the room edge.

I may have taken it for granted that this would be taken into consideration (considering I copied the manual entry here).

@Construed: I've never actually used the function myself, so I was just going off the manual entry, but from what I gather it's generally intended for use with the "walks off edge" room event functions. That is, when entering the new room, it should place the character along the specified edge, which wouldn't trigger the "walks off edge" events. Depending on how you had your hotspots and their respective events set up, that may have caused issues trying to combine the two mechanics (it could probably be done, but you'd have to understand what's happening of course).

It looks like you got it sorted though, so. (roll)


festilligambe

Instead of a hotspot you could use edges, in the room screen under the pulldown that had objects and hotspots ect is one called edges it brings up horizontal and vertical lines you can drag on the screen to mark the top bottom left and right of the room. The in the room events (lightning bolt) you can choose walks off bottom top left right depending on the code you want to run.  So choose left and enter the player.ChangeRoomAutoPosition code there then the player's feet hit that line it will execute the code, This way you do not need a hotspot and can change when a character changes the room just by sliding that line.
New to programing, old school to adventure games

Construed

Yes sir, After changing 80 4-way rooms from hotspots to edges, all is well in Grim Quest!

I feel like the hero in QFG1 when he got done raking for the stableman!

Thanks to everyone for the patience and help!

Have a blessed day!

-Jar Head
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

SMF spam blocked by CleanTalk