Store player X,Y location from room

Started by Icey, Tue 02/08/2011 05:32:22

Previous topic - Next topic

Icey

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 :(

lilinuyasha

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.
I can Fluently speak Braille. I obtained a swiss army knife...From the Turkish Navy. My hands feel like rich brown suede. My blood smells like cologne. I AM Trey Love, The most Interesting Man in the World.

Icey

#2
Sure I could do I that but I would like to give the random thing a try this time around.

lilinuyasha

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,.
I can Fluently speak Braille. I obtained a swiss army knife...From the Turkish Navy. My hands feel like rich brown suede. My blood smells like cologne. I AM Trey Love, The most Interesting Man in the World.

Khris

Create two global int variables, e.g. px & py.

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

Code: ags
  px = player.x;
  py = player.y;


After winning the battle, call

Code: ags
  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.)

Icey

#5
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:

monkey0506

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:

Code: ags
// 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:

Code: ags
player.ChangeRoomSaveXY(BATTLE_ROOM);


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

Code: ags
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. ;)

Icey

I don't think I have worked wit extenders yet. However one day I would like to try.

R4L

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

SMF spam blocked by CleanTalk