Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Lewis on Thu 22/11/2012 20:10:46

Title: Problems with character.ChangeRoom when character is elsewhere in the game
Post by: Lewis on Thu 22/11/2012 20:10:46
I know, I know, I'm posting a ridiculous number of questions at the moment. (I've taken a week off work to try to make loads of progress with my game, and it seems I'm just running into problem after problem that I can't find a solution for.)

I'm having a bizarre issue with non-player characters changing rooms. Specifically, the issue seems to be with changing the rooms of characters who are not in the same room as the player at the time.

So, for example, if I leave cCharacter2 in Room 1, then later enter Room 3, I want cCharacter2 to be in Room 3 when I arrive.

I've tried calling cCharacter2.ChangeRoom(3) upon leaving Room 1, upon entering Room 3, and at various random points in between, but for some reason the character is just not changing rooms. I've been bashing my head against a hundred walls all afternoon with this, and I'm at the stage now where if I try any more workarounds I'm just going to screw up a whole load of other things in the game. It's starting to really stress me out.

I think this is the issue, anyway. The weird thing is that if I start the game from a certain later point, things seem to work more or less normally - the issue only seems to crop up if I play the game from the start. So I'm not sure if there's some earlier code that's messing things up, which makes having someone else look at the code a difficult thing.

Any pointers hugely appreciated. I'm tearing my hair out here, and it's probably something super-obvious.
Title: Re: Problems with character.ChangeRoom when character is elsewhere in the game
Post by: geork on Thu 22/11/2012 20:58:50
I dunno is this'll help: try setting the co-ordinates you want cCharacter2 to go, so:
Code (AGS) Select
cCharacter2.ChangeRoom(3,200,200)
it ay be that he HAS changed room, but sits in an awkward place...

this is a very hasty reply, so it's probably not the issue - my apologies if I am wasting time
Title: Re: Problems with character.ChangeRoom when character is elsewhere in the game
Post by: Volcan on Thu 22/11/2012 22:15:32
I'm not sure about your question. I'd use variables for this:

Code (AGS) Select
if (Story==3)
{
cCharacter2.ChangeRoom(3,160,100);
}
Title: Re: Problems with character.ChangeRoom when character is elsewhere in the game
Post by: Khris on Fri 23/11/2012 00:54:40
If you run the game in debug mode, you can press CTRL-D to get info about characters inside the current room (coords, view, etc.)

The place to move NPCs around is definitely the before fadein event; maybe it's a bit silly to ask this but are you sure that it's actually room 3 you're entering? You can always use cNPC.ChangeRoom(player.Room); to stay independent of AGS's numbering of the rooms.

Also double-check if the character might get moved off-screen, that their view contains sprites and that they aren't transparent or behind a walk-behind or object; and of course make sure that the function is actually called: if a Display("x happens"); is inconvenient for the event, you can always play a short sound instead.

I know that this isn't helping but your problem is almost certainly a user error, not an engine bug.

You don't need workarounds to put a character in a room, and if you try those and it screws up a whole load of other things, as you say, it really makes me wonder what else is going on.