Only Once

Started by Flyman, Sat 28/01/2012 15:38:32

Previous topic - Next topic

Flyman

 need help...

mmm, how can a character open a door with a key and after see a ghost say: "Oh my
God", but this only the first time a open the door
after everytime when he open  the door say: "mmm it's only a ghost"!
I think, I must set another setglobal in my script ...but how??

// script for Hotspot 6 (Door): Any click on hotspot

if (UsedAction (A_OPEN)) {
  if (MovePlayer (338, 137)) {
    FaceDirection (GetPlayerCharacter(), DIR_UP);
    Wait (10);
    if (GetGlobalInt(3)==0){
      DisplaySpeech(GetPlayerCharacter(), "Close.");
    }
    else if (GetGlobalInt(3)==1){
    PlaySound(2);
ObjectOn(1);
    object[2].SetView(49, 0);
ObjectOn(2);
PlaySound(98);
  object[2].Baseline = object[1].Y + 1;  \\animated of the ghost
object[2].Animate(0, 1);
DisableHotspot(6);
    FaceDirection (GetPlayerCharacter(), DIR_RIGHT);
    Wait (10);
    DisplaySpeech(GetPlayerCharacter(), "Oh my God.....");
    }
  }
}

else Unhandled ();

// script for Object 1: Any click on object

if (UsedAction (A_USE_INV)) {
  if (character [GetPlayerCharacter ()].activeinv == 7) {
    if (MovePlayer(338, 137)){
    FaceDirection (GetPlayerCharacter (), DIR_UP);
    Wait(5);
    PlaySound(3);
    ObjectOff(1);
    Wait(5);
    PlaySound(46);
    SetGlobalInt(3,0);
    EnableHotspot(6);

thanks

Rulaman

The help says the following:
--

static bool Game.DoOnceOnly(const string token)

This function gives you an easy way of making some code run only the first time that the player encounters it. It is commonly used for awarding points.
The token parameter is an arbitrary string. You can pass whatever you like in for this, but IT MUST BE UNIQUE. It is this string that allows AGS to determine whether this section of code has been run before, therefore you should make sure that you do not use the same token string in two different places in your game.

Returns true the first time that it is called with this token, and false thereafter.

NOTE: This is a static function, and thus need to be called with Game. in front of it. See the example below.

Example:

if (Game.DoOnceOnly("open cupboard")) {
  GiveScore(5);
}

will give the player 5 points the first time this script is run.
See Also: GiveScore



So you can use:
--

if   (Game.DoOnceOnly("open door with ghost") )
{
  player.Say("Oh my God.");
}
else
{
  player.Say("mmm it's only a ghost!");
}
Zak: Komm mit mir Sushi.
Zak: Come with me Sushi.

Flyman

Thanks! I've just update to AGS 3.1 and have resolved!!

SMF spam blocked by CleanTalk