Wintermute Engine > Not a bug

Declaring and setting globals in same statement unreliable?

<< < (2/2)

Mnemonic:
Acknowledged but still no info provided :-\
There are many factors that can affect this. For example, is your TakeItem method overridden? Does the handler with this code contain some "blocking" method, such as Talk, GoTo, PlayAnim?
Saying "hey! there's a bug but I won't tell you anything about it" is kind of... useless.

Mnemonic:
And judging by this thread you are indeed using an overridden TakeItem() method. So one innocently looking line actually calls much more code under the hood. That's why knowing the context is extremely important when diagnosing "bugs"...

Kaz:
Mnem

I humbly and apologetically take your point. The overriding TakeItem from game.script:


--- Code: ---method TakeItem(var ItemName)
  {
  // call the original method we have just overriden
  this.TakeItem(ItemName);
  global InventoryOn;
  if(InventoryOn == true)
    {
    Game.PlaySound("sounds\ToInventory.ogg");
  global InventoryHint = true;
  Sleep(1000);
  InventoryHint = false;
}
  }

--- End code ---

The full script where the method is called:

--- Code: ---#include "scripts\base.inc"
#include "scripts\keys.inc"

self.GoExclusive();

on "LeftClick"
  {
  var a = Game.IsItemTaken("LetterRhiannon");
  if(a == true)
    {
Game.PlaySound("sounds\NoticeboardOn.ogg");
}
  else
    {
    Game.TakeItem("LetterRhiannon");
global gGotLetterRhiannon = true;
    }
  self.Close;
  Game.UnloadObject(this);
  }

--- End code ---

The script that checks whether the letter is in inventory as a condition on an action:


--- Code: ---if(gFAC.Seen != true)
  {
  global gFireIsLit;
  global gGotLetterRhiannon;
  if(gFireIsLit != true || gGotLetterRhiannon != true)
    {
    // Fire not lit or study not visited - just rattle the door
    Game.PlaySound("sounds\LockedSuffolkDoor.ogg");
gRhiannonHaunt.TriedDoor = true;
}
  else
    {
// Play the FAC sequence
    Game.Interactive = false;
gRhiannonHaunt.Summon = false;
    Game.PlaySound("sounds\LockedSuffolkDoor.ogg");
    Sleep(1000);
    Game.SetMousePos(1024, 768);
    var video = Scene.GetNode("video");
    video.Active = true;
    video.PlayTheora("Video\FAC.ogg");
    Sleep(20000);
    video.Active = false;
// This gFAC.Seen = true will prevent the Summons from running again
    gFAC.Seen = true;
    gFAC.Solved = false;
    Scene.InitializeDoor();
    Game.Interactive = true;
}
  }

--- End code ---

Anything you can suggest as to why it works usually, but not always?

Thanks

Mnemonic:
Thanks :)

Now, what happens if the player clicks the window, and then, while the game is displaying the acquired item for one second, he clicks the window again? The LeftClick handler is executed again, it will find the item is already taken, so it will just play some sound and kill the window. Killing the window will also kill the original LeftClick handler, which is still executing the TakeItem line (waiting for one second) so it will never get to the second line.

A good practice is to enclose atomic actions invoked by player between Game.Interactive = false / true. That way the player cannot click again until the original click handler finishes.

Kaz:
Of course! Hemm, I mean, that sounds reasonable. No wonder you smiled  :)

We'll test it.

Ah - double-clicked it as fast as I could. And it worked as it should. :(

Never mind, your suggestion sounds right, so we'll lock the routine down.

Thanks

Navigation

[0] Message Index

[*] Previous page

Go to full version