Is changeRoom the ONLY way to change a characters' room? (SOLVED)

Started by EnterTheStory (aka tolworthy), Tue 09/06/2009 20:40:47

Previous topic - Next topic

EnterTheStory (aka tolworthy)

I call character[npc].changeRoom(player.Room,x,y) in the middle of a function. But the character remains in his old room. By inserting Display("text") at key points I can briefly see the character appear, but then he's gone before the function ends. Yet I never told him to go away. So...

1. Is there any other mechanism that can change a character's room?
2. Is it possible that 'changeRoom' could be called, then canceled later in the same function?

I can post the code if you like, but the relevant functions are about ten pages long.

GuyAwesome

AFAIK, the answer to both questions is 'No', (unless you're using 2.72 or earlier, and there's an Interaction Editor command at work). The only way a character should be able to change rooms is if you tell it to.

Have you tried inserting a Display (e.g. Display("%d", character[npc].Room);) command to check where the character goes? Without more info, it might be that the char isn't changing rooms, but is being hidden somehow - walkbehinds, changing view, character[npc].on = false, etc... - so making sure it IS being moved out again is a place to start.
Given how long you say the functions involved are, is it possible there's something you've overlooked that might be moving/hiding your character? Or something in repeatedly_execute, perhaps?

JpSoft

Quote1. Is there any other mechanism that can change a character's room?
No, AFAIK. ChangeRoom is the function specially designed for this job.
Quote2. Is it possible that 'changeRoom' could be called, then canceled later in the same function?
Im not sure about this, but i guess not. You can insert a variable which can be updated and verified into the same function and then decide what to do next.

Trent R

There was a recent thread dealing with moving the character on screen instantaneously (solution being to change the xy values directly) in which someone suggested using ChangeRoom to the same room. Perhaps that would fix your second problem?


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

GuyAwesome

Heh, I was reading the second question as 'Is there anything that could be making this happen automatically, causing the problem', which is why it was a 'No'. If you WANT it to happen - I still don't think there's a built-in function for it, but you can probably script it, as the others said.

EnterTheStory (aka tolworthy)

Quote from: GuyAwesome on Tue 09/06/2009 21:11:32'No', (unless you're using 2.72 or earlier, and there's an Interaction Editor command at work).
I am. so I'll look into that. Thanks.

Quote from: GuyAwesome on Tue 09/06/2009 21:11:32Have you tried inserting a Display (e.g. Display("%d", character[npc].Room);) command to check where the character goes?

I've spent the last two days adding those infernal messages :( When messages are inserted, the code slows down and runs perfectly. Which makes me think it's a queuing problem. Without those delays the code simply doesn't do what I tell it to do.

GuyAwesome

Does the NPC stay in the room permanently when the delays are there, or just for long enough that you knew they WERE there? That display line after the fade in (based on your pre-edit post) should at least tell you if they're still in the right room.

EnterTheStory (aka tolworthy)

Quote from: GuyAwesome on Tue 09/06/2009 22:55:20
Does the NPC stay in the room permanently when the delays are there, or just for long enough that you knew they WERE there?

Permanently.

Anyway, after two days of experimenting I've decided to cut the Gordian knot and just re-write my 'add NPC to room' code, making it much simpler.

Thanks everyone for your replies.

RickJ

The character is moved to the new room by the engine.  The script queues up the request but it is not executed until control is returned from the script to the engine.   For example if you move a character from poiny A to point B and then back to point A in the same script the character will remain at point A.

EnterTheStory (aka tolworthy)

FOUND IT! After two days, and stripping back the code to bare bones (and then commenting it out to within an inch of its life) I traced the evil and exorcised it.

The answer to the question. "can any other function change a character's room" is yes. The function is followCharacter.

To recap, using 'ChangeRoom' caused my NPC to obediently change rooms (I saw him there on screen during the 'Display' message). Then as soon as the function ended he immediately changed rooms back again, as if being snapped back on a piece of elastic.

It appears that during an earlier cutscene my NPC had briefly followed another NPC. Originally I ended that sequence by setting 'followCharacter' to null, but somehow that line got deleted. It didn't strike me as significant, because I thought a 'dormant' room could not reach out from beyond the grave and kidnap a character from an 'active' room. Shows how wrong I was!

GuyAwesome

I'd say it wasn't the 'dormant' room reaching out and grabbing the character, but the 'active' room realising they shouldn't be there and booting them out. After all, if a character is set to follow someone, they should always be in the same room (except for the brief delay after the Followee changes rooms). I wonder if the engine would 'notice' if you moved the Follower from one 'dormant' room to another and move them back, or if it'd only catch up when the player went there? Completely irrelevant, of course, but curious.

SMF spam blocked by CleanTalk