Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: lilinuyasha on Thu 26/02/2015 20:43:29

Title: Starting a dialog with an if/then statement
Post by: lilinuyasha on Thu 26/02/2015 20:43:29
I just got back to AGS after taking a short sabbatical.

Now, I'd like a specific dialog to start only after a character that had been following the player enters the room. I know this is going to be an "Enters after fade in" if/then statement, but I'm not sure of the proper command to check for it.

The characters script name is cAngel, and is following our character. After checking dynamic help, i can't seem to find a "Character enters room" function or similar.
Title: Re: Starting a dialog with an if/then statement
Post by: Ibispi on Thu 26/02/2015 22:38:21
Hi lilinuyasha,
I don't know if any function exists in ags about a certain character entering a room. :undecided:
This event could be easily custom created though! (nod)

Here's how I would do it if I were you:
STEP 1#:
Create a global boolean:

I go into "Global variables" tab (it is in between Audio and Scripts tabs in my AGS editor version).
II right click on that blank space and click on "Add new variable".
IIItype the name of the variable "CharEntered0"*            *the name of the variable can be anything you want
IV for variable type choose "bool".
V type in false as a default value
STEP 2#:
Create a trigger for the event:

I Open GlobalScript.asc
II find a repeatedly execute function and type in this:
// put anything you want to happen every game cycle in here
function repeatedly_execute()
{   
    if((CHARNAME**.Room==1)&&(CharEntered0==false)){
        CharEntered0=true; /* the bool is required so that the repeatedly execute function doesn't loop forever */
        //and add here everything you want to happen after the event is triggered
}

**instead of CHARNAME type in the script name of your character e.g. cRoger.Room==1...

Tell me if you have any problems or questions! :-)
Title: Re: Starting a dialog with an if/then statement
Post by: lilinuyasha on Thu 26/02/2015 23:58:33
That seems pretty complicated. I'll try it when I get back to my working hours.
Title: Re: Starting a dialog with an if/then statement
Post by: lilinuyasha on Mon 02/03/2015 18:55:18
It worked! Thanks, man!
Title: Re: Starting a dialog with an if/then statement
Post by: Ibispi on Mon 02/03/2015 19:18:19
Quote from: lilinuyasha on Mon 02/03/2015 18:55:18
It worked! Thanks, man!
Great! :^)
Title: Re: Starting a dialog with an if/then statement
Post by: Monsieur OUXX on Tue 03/03/2015 14:13:05
For the record : "Global Variables" are the old, graphical way of storing a permanent value in your game. You create them with the Editor interface.

Another way is just to declare a variable in your global script or, even better, in your room script (if you want it to affect only this room):
Code (ags) Select

//in your gloabl script or room script
bool CharEntered0=false;

...

//in your room script
if (CharEntered0==false...


Just do it any way you like most.