Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Icey on Tue 02/08/2011 05:32:22

Title: Store player X,Y location from room
Post by: Icey on Tue 02/08/2011 05:32:22
In my game I would like to have the player change a room at random when walking. I would like to save the players X,Y location and then after the player completes the battle and the room they are sent back to the saved location. I don't really know how to this up :(
Title: Re: Store player X,Y location from room
Post by: lilinuyasha on Tue 02/08/2011 05:58:26
I don't really use random, but depending on what you're trying to do with the script, send the character to a different room while the battle occurs. Then, have him exit when the battle is done, and your character will be back there.
Title: Re: Store player X,Y location from room
Post by: Icey on Tue 02/08/2011 06:03:50
Sure I could do I that but I would like to give the random thing a try this time around.
Title: Re: Store player X,Y location from room
Post by: lilinuyasha on Tue 02/08/2011 06:05:40
I'm not sure if that was English, but you may want to wait until some more technologically advanced people get in here. My games tend to be very simplistic coding,.
Title: Re: Store player X,Y location from room
Post by: Khris on Tue 02/08/2011 08:07:02
Create two global int variables, e.g. px & py.

Then, before sending the player off to the random battle room, use:

  px = player.x;
  py = player.y;


After winning the battle, call

  player.ChangeRoom(player.PreviousRoom, px, py);

I hope now you know how to this up. ( :o ::) where's the facepalm smiley?)

(Don't create multiple battle rooms, btw, especially not if you're going to copy and paste the entire battle/room script. This is NOT the way it's done.)
Title: Re: Store player X,Y location from room
Post by: Icey on Tue 02/08/2011 08:42:31
Thanks Khris, I thought I needed variables for this but I didn't know how to set it up.

Also I plan to use one room for different areas. I think I know how to randomly generate enemies for the rooms and apply their separate variables for them.

Also here you go: (http://www.pictureshoster.com/files/skipq7ltwfxcgob0t22.png)
Title: Re: Store player X,Y location from room
Post by: monkey0506 on Wed 03/08/2011 06:35:20
At the risk of making your game explode if you can't figure out how to copy/paste right (:P), you could even use extender methods:

// GlobalScript.ash

import void ChangeRoomSaveXY(this Character*, int room_number, int x=SCR_NO_VALUE, int y=SCR_NO_VALUE);
import void ReturnToPreviousRoomAndPosition(this Character*);

// GlobalScript.asc

void ChangeRoomSaveXY(this Character*, int room_number, int x, int y)
{
  if (this == player)
  {
    px = this.x;
    py = this.y;
  }
  this.ChangeRoom(this, room_number, x, y);
}

void ReturnToPreviousRoomAndPosition(this Character*)
{
  if (this != player) this.ChangeRoom(this.PreviousRoom);
  else this.ChangeRoom(this.PreviousRoom, px, py);
}


Then when you change to the battle room:

player.ChangeRoomSaveXY(BATTLE_ROOM);

And when going back, you could just use the normal function:

player.ReturnToPreviousRoomAndPosition();

Doesn't affect much of anything (compared to what Khris already said) except your workflow of course, but it's just a thought. ;)
Title: Re: Store player X,Y location from room
Post by: Icey on Thu 04/08/2011 01:37:48
I don't think I have worked wit extenders yet. However one day I would like to try.
Title: Re: Store player X,Y location from room
Post by: R4L on Thu 04/08/2011 03:51:01
Quote from: Studio3 on Thu 04/08/2011 01:37:48
I don't think I have worked wit extenders yet. However one day I would like to try.

Today is that day.  :P