Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Pogwizd on Sun 28/02/2021 16:37:58

Title: Calling .walk() right after .setAsPlayer()
Post by: Pogwizd on Sun 28/02/2021 16:37:58
Hi, I've got a question about how to script whole cut-scenes that involve changing rooms/characters and keep them in one function.

In my current code I am trying to change the room and the player at the same time and then make the character go to a certain position. So the code looks pretty much like this:

Code (ags) Select

cSuper.SetAsPlayer();         
player.Walk(1334, characterYPos, eBlock, eWalkableAreas);


From the documentation I know that if the given character is not in the current room, .setAsPlayer() changes room to the one the new player-character is currently in. And this part works fine, however, if I add .walk() the game produces an error saying that "character not in current room".

If I display player.Room, it returns me the correct id (after the room change), so I don't really know why I am getting the error. I am assuming it's got sth to with the room not being fully loaded before .walk() is called (but this is just a wild guess of mine).
Is there a way to do this?

Thanks!
Title: Re: Calling .walk() right after .setAsPlayer()
Post by: Matti on Sun 28/02/2021 16:44:01
The script is being finished before the room changes which means you're trying to make the player walk in a different room which is not possible.

You should put the walk command in the script of the room the player changes to, most suitably the after-fadein-function.
Title: Re: Calling .walk() right after .setAsPlayer()
Post by: Pogwizd on Sun 28/02/2021 16:48:09
OK, good to know. Thanks for your help!