Previous room for 1 person game.

Started by td, Tue 01/08/2006 12:15:27

Previous topic - Next topic

td

I trying to add
character[EGO].PreviousRoom;
function when some keycode is pressed (403 for example) . But my character is hide (therefore i haven't character) coz i make 1 person game. So the code must be:

if (keycode==403) ....

And then???

SSH

The player character still exists, even if they are invisible, so you can use player.PreviousRoom.
12

Khris

#2
player.PreviousRoom only returns the previous room's number; you probably want to use
Code: ags
if (keycode==403) player.ChangeRoom(player.PreviousRoom);


rtfm...

td

#3
Thanks Khris. That Is that!

EDIT:
Yes. But in some moments in my game PreviousRoom function must be blocked (player can't back).
How can i blocked this, Khris?

Ashen

You could add an on_key_press function to those rooms, using ClaimEvent() to block the main one:

Code: ags

// Room script
function on_key_press (int keycode) {
  if (keycode == 403) ClaimEvent();
}


Or, you could create a Custom Property that determines whether or not backtracking is allowed. E.g., create a boolean property called 'AllowBack', and change the Global on_key_press condition to:
Code: ags

if (keycode==403 && GetRoomProperty("AllowBack") == true) player.ChangeRoom(player.PreviousRoom);


If it's just at specific times you want backtracking disabled (e.g. the player enters the room and the door locks behind them - can't go back untill they unlock it), just create a script variable, and have on_key_press check that instead/as well.
I know what you're thinking ... Don't think that.

td

Respect+ Ashen! Very informative...

td

Line
  if (keycode==380) player.ChangeRoom(player.PreviousRoom);
is work,but here is a problem i meeted:
For example i visited rooms: 1>2>3>4
If i press button (380) i retuned : 4>3>4>3 etc.  I thought it must be 4>3>2>1 and i need right this.

How can i change this?

monkey0506

You could try:

if ((keycode == 380) && (player.Room > 1)) player.ChangeRoom(player.Room - 1);

SMF spam blocked by CleanTalk