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 :(
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.
Sure I could do I that but I would like to give the random thing a try this time around.
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,.
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.)
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)
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. ;)
I don't think I have worked wit extenders yet. However one day I would like to try.
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