AGS 2.3.1 First time a player enters the room?

Started by Edv1983, Wed 27/07/2011 13:15:54

Previous topic - Next topic

Edv1983

Hello!

I'm sure this is a really stupid question.  I'm trying to create an animation where a car drives down the road after fadein without any user interaction.  I think I need to use the first time a player enters the room but I cant seem to find an example of it in code.  

Any help would be appreciated

Khris

(I guess you mean 3.2.1, not 2.3.1, right?)

You have to create the function (code) and link it to the event (first time player enters screen).

To do that, open the room and click the lighting bolt icon above the room properties list (below the project tree).
In there, click the event, then click the ellipses button that appears in the empty field next to it.
This will create the empty function, put the name in the previously empty field (thus linking event and function) and open the room script so that you can immediately put code into the function's body, between { and }.

This general process is explained in the tutorial's part 3, Hotspots and Events. (Helpfile -> Tutorial -> Starting off)

Ghost

It IS a basic question, but there have been stupider(?) ones.

You set up the event handler by going to the room's event tab (press the little flash icon), and then the ... next to "First time enters room".
This will give you an empty handler:
Code: ags

function room_FirstLoad()
{

}


Now, depending on how you want to have the animation implemented (a character animating, or an object, you just put it there.
I suggest to create an object in the room, set it just outside the actual screen (using the x/y coordinates), and then move it along.
If you need an actual code example for that, too, just create an object and name it oCar, then:

Code: ags

int carX = oCar.X;
function room_FirstLoad()
{
  while (oCar.X < 400)
  {
    oCar.X+=4;
   Wait(1);
   }
}


This will move your car from its starting position all the way through a 320x240 room, pausing the game for the player as it does so, and then return control to the player.

[edit]
Ah, dang is, Kris! ::)

Edv1983

Thankyou... I swear I've looked at the events multiple times and never found the first time enters room... must be going blind.

SMF spam blocked by CleanTalk