Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Anarcho on Tue 19/04/2005 02:00:34

Title: Saying something only once
Post by: Anarcho on Tue 19/04/2005 02:00:34
Sorry for the strange subject,

I've got a situation where the player is in one room, something happens and she's transported to the next room.  I want some code to run, and then I want her to say something only once after she enters the room on that occasion.  She's been in the room before, so I can't just use the first time player enters screen thing in the editor.  I feel like there must be an obvious way to do this.  I've been looking through the help file index, but can't find something applicable.

As it is right now, I put this code in the Player Enters Screen after Fadein section of the room's interaction editor, after a conditional if she has an inventory item (right before the transport she gains an inventory item).  The problem is, after she gets the inventory, she always says the message when she enters that room.

help?



Title: Re: Saying something only once
Post by: stuh505 on Tue 19/04/2005 02:04:22
Since the condition you're checking does not depend purely on any states that the game can check (such a inventory or the number of times the area has been visited), you will need to create a variable with global scope to keep track of this.  There's plenty of talk on Global Variables in this forum so if you get stuck just do a search or check the manual.
Title: Re: Saying something only once
Post by: Anarcho on Tue 19/04/2005 02:57:17
I figured that I would have to use Global Variables, I'm just not sure how to use them in this situation, which is why I posted the previous message.

What would the variable be applicable to?  I'm used to using them for if you interact with an object, and need to change the interaction and stuff like that...but this is all concerning a room. 
Title: Re: Saying something only once
Post by: stuh505 on Tue 19/04/2005 03:02:49
Name the variable logically.  Here's an example:


int bMariahTalked1 = 1;

if (bMariahTalked1 == 1)
{
}

The "b" indicates that it is a boolean value which is true/false ie 1/0.

For each situation involving mariah I might want to have different boolean counters.

Another option is, if I know Im going to have Mariah say different things a lot of the time depending on the situation, I can just have 1 variable like, "nMariahTalkState"...and then I can set this to different values, and check what value it is at any time.
Title: Re: Saying something only once
Post by: Anarcho on Tue 19/04/2005 03:31:16
Hmmm, thanks for trying, but I don't get it.  I guess I'm not familiar enough with Global Variables to do it.  Instead, I've just given the player an invisible inventory item that is taken away once the script ends in the next room.  I think it should work---though it's sorta silly.
Title: Re: Saying something only once
Post by: stuh505 on Tue 19/04/2005 03:36:25
Ok, here's some pseudocode:

int bSarahTalked = 0;

If (bSarahTalked == 0)
{
  Sarah.Say("Hello");
  bSarahTalked = 1;
} else if (bSarahTalked == 1)
{
  Sarah.Say("Hello again");
  bSarahTalked = 2;
} else if (bSarahTalked == 2)
{
  Sarah.Say("why do you keep coming bacl?");
  bSarahTalked = 3;
}

Talk to Sarah three times and shell say:

Hello
Hello Again
Why do oyu keep ocming back?


And never say anyting again..
Title: Re: Saying something only once
Post by: Gilbert on Tue 19/04/2005 03:45:42
Well you can create a global variable like stuh mentioned (but then you have to go for that export/import route).

Alternately , you can use those predefined Global Ints, the draw back is you can't use descriptive names (well you can define names for the GlobalInt # though) and need to use functions to manipulate them.

There're 500 available Global Ints, all can be accessed via the functions SetGlobalInt() and GetGlobalInt().

You can just decide to use one of them to record the state of something done. Say, if you use Global Int #10 for it.

Note that it's initially set to 0, whenever the player archieves something in the game you can set the variable to some other value to indicate the state, eg:

SetGlobalInt(10,1);

For places where you want the game to react differently according to the value of the variable, you can do something like:

if (GetGlobalInt(10)==1) {
Ã, //do something bla bla
} else {
Ã, //do some other thing
}
Title: Re: Saying something only once
Post by: on Tue 19/04/2005 04:18:26
Ah, so you can do it with Global Ints.  I'm more familiar with that.   I guess I just wasn't sure where to put the code.  But basically the integer I choose would normally be set at zero meaning she would say nothing in that room, but then when she transports into the new room I'll set the integer to 1 with her saying something, then set it back to 0?

But where would I put the code?
Title: Re: Saying something only once
Post by: Gilbert on Tue 19/04/2005 04:57:07
If you want something to happen only when the character is teleported from room A to room B and don't want it to happen when she enters room B normally, you can put that SetGlobalInt() just before the teleportation.
Eg, in room A where the teleporting occurs:

SetGlobalInt(10,1);
player.ChangeRoomEx(B,x,y); //well I think you're using V2.7, use NewRoomEx(0 for previous versions

Then in room B, if you want that "something" to happen just after she enters the room, put in enter room after fade in:

if (GetGlobalInt(10)==1) {
  //Do whatever you want blah bla
  SetGlobalInt(10,0); //reset it so it won't be executed again next time
}
Title: Re: Saying something only once
Post by: Anarcho on Tue 19/04/2005 14:21:46
Oh I see, thanks for walking me through it.  That's not so complex after all.