[Solved]How to change room after playing a song & animation

Started by doctorhibert, Sun 17/09/2017 00:23:01

Previous topic - Next topic

doctorhibert

Hi, sorry for posting another question, came back to my game and it's like walking into a burning building, I have no idea what I was doing

Anyways, I have a room where I have an object the size of the background (it's a cutscene), An animation plays and once it's done a song starts playing. Now this works fine and I accomplished it with this code:

Code: ags

function room_Load()
{
ofondo.SetView(HITITVIEW);
 ofondo.Animate(0,  1, eOnce,  eNoBlock);

}

function room_AfterFadeIn()
{

 Wait(25);
 aintro.Play();
]

So as you can see, as the room loads the animation plays, I have a wait for 25 loops and then the music plays, this works just fine, now my problem is that I want the room to change as soon as the music starts.

I tried making a wait loop after aintro.play(); but it just changes the room before the earlier 25 wait loop is done. Then I tried making some jury rigged magic with an unused character to see if I could get it to wait until the music started playing to change the room. This is what I came up with

Code: ags


function room_Load()
{
ofondo.SetView(HITITVIEW);
 ofondo.Animate(0,  1, eOnce,  eNoBlock);

}

function room_AfterFadeIn()
{

 Wait(25);
 aintro.Play();
 Wait(1);
 cguardia.ChangeRoom(19, 10,  10);
cguardia.Move(10,  15);

if (cguardia.y==15){
player.ChangeRoom(20);
}
}


So basically, after the music, it moves a character to the room and moves it to a location, and when it moves there it's supposed to change the room, but of course this doesn't work because I suck at programming, so I don't know what to do or how to do it. Any help is appreciated

eri0o

Hey, I don't know if it's your case, but I thought you should know the following detail on changeRoom isn't instantaneous from the AGS Manual.

Also I don't think you can call character move when it's in another room.

Quote
ChangeRoom

Changes the room that the character is in.

If you call this on the player character, then the game will move into the new room with them.

IMPORTANT: This command does not change the room immediately; instead, it will perform the actual room change once your script function has finished (This is to avoid problems with unloading the script while it is still running). This means that you should not use any other commands which rely on the new room (object positionings, and so on) after this command within the same function.

If you call this on a non-player character, then they are instantly transported to the new room number.

Scorpiorus

As for the original question, a simple Wait(...) command should actually work:

Code: ags

function room_Load()
{
    ofondo.SetView(HITITVIEW);
}
 
function room_AfterFadeIn()
{
    ofondo.Animate(0, 1, eOnce, eBlock); // changed to eBlock to wait until the animation finishes!
    Wait(25);
    aintro.Play();
    Wait(120); // wait 120 loops (or around 3 seconds with the default frame rate of 40 fps)
    player.ChangeRoom(20);
}


Otherwise, if it doesn't work, post your exact scripts.

doctorhibert

So it really was that easy. Thanks, that worked.

SMF spam blocked by CleanTalk