Game authors and players, please read this thread!

Author Topic: Change room without the player  (Read 393 times)  Share 

Spiderhund

    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Change room without the player
« on: 02 Apr 2009, 17:38 »
Hey.
I've ran into another problem with my game.
I've been looking through the manual and on the forums but found nothing.

I want to be able to change room without moving the player to that room so that when I return from that room the player will be in the exact same position as when I left.
It's because I want a map that the player can bring up and then close again when they're done using it. I don't what to use a GUI for this because I want some objects on it that the player should be able to move around on the map.

So the way I would do this is to when the player clicks on the "Open Map" button it will save his current Room ID, Position X and Position Y to 3 different Global Variables then using the "ChangeRoom" command to go to the map room. Then when the player clicks on the "Close Map" button (In the map room) It will use the 3 Global Variables (Room ID, Pos X, Pos Y) to restore where the player was when he opened the map.


Is this the best way to do this or is there another maybe easier way of doing it?
Thanks in advance.

Re: Change room without the player
« Reply #1 on: 02 Apr 2009, 17:48 »
I tend to stick a camera character in the room, like cMapCamera. Make it invisible on room load with cMapCamera.Transparency = 100;

Then you can:

cMapCamera.SetAsPlayer() whenever you like to cut to that room, and cPlayer.SetAsPlayer to return to your chappy.
« Last Edit: 02 Apr 2009, 17:50 by thezombiecow »

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: Change room without the player
« Reply #2 on: 02 Apr 2009, 17:49 »
Sure thing. Set your "map" room to not show the player (ShowPlayerCharacter in the room's properties pane to false). Then when you open the map:

[code]player.ChangeRoom(MAP, player.x, player.y);[/code]

When you close the map:

[code]player.ChangeRoom(player.PreviousRoom, player.x, player.y);[/code]

Edit: Just beat me zombie. But that would work as well. ;)
« Last Edit: 02 Apr 2009, 17:50 by monkey_05_06 »
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Re: Change room without the player
« Reply #3 on: 02 Apr 2009, 17:49 »
Whoops sorry, quoted instesad of editing!

:)

Re: Change room without the player
« Reply #4 on: 02 Apr 2009, 17:52 »
The coordinates are even optional parameters, so you can just do player.ChangeRoom(MAP) and player.ChangeRoom(player.PreviousRoom).

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: Change room without the player
« Reply #5 on: 02 Apr 2009, 17:56 »
I wasn't 100% sure if omitting the parameters defaulted to the character's current (X, Y) or what. The manual is a bit unclear on that. :P Of course you may then also want to make sure you claim the event for the map room. A lot of games use PlaceOnWalkableArea in eEventEnterRoomBeforeFadein globally, so in the room script you would additionally use:

[code]function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    ClaimEvent();
    return;
  }
}[/code]

Or just make sure the entire map is marked as walkable.
« Last Edit: 02 Apr 2009, 22:39 by monkey_05_06 »
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Spiderhund

    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Change room without the player
« Reply #6 on: 02 Apr 2009, 21:43 »
Thanks guys :)
Now I should be able to add a (maybe kinda cool) feature I've been thinking of :D