Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Darky on August 07, 2009, 01:35:44 PM

Title: Change Item Caption after Interactions
Post by: Darky on August 07, 2009, 01:35:44 PM
I am trying to change the Caption of an Item after the Player looked at the item. It displays "Normal Item Name" as it should and according to Debug after looking at the Item the ItemStatus.LookedAt is indeed "true". However, the Item Name does not change. Does anybody know why and what I do wrong?

Here is the Code:

Code: [Select]
var ItemStatus;
ItemStatus.LookedAt = false;

////////////////////////////////////////////////////////////////////////////////
on "LookAt"
{
actor.GoToObject(this);
actor.Direction = DI_UP;
ItemStatus.LookedAt = true;
actor.Talk("Interesting");
}

// change caption
if(ItemStatus.LookedAt == true)
{
this.Caption = "Changed Item Name";
} else {
this.Caption = "Normal Item Name";
}
Title: Re: Change Item Caption after Interactions
Post by: Mnemonic on August 07, 2009, 03:26:57 PM
Because if you put the code to this place, it's only executed when the script is loaded for the first time. You want something like this:

Code: WME Script
  1. var ItemStatus;
  2. ItemStatus.LookedAt = false;
  3.  
  4.  
  5. ////////////////////////////////////////////////////////////////////////////////
  6. on "LookAt"
  7. {
  8.   actor.GoToObject(this);
  9.   actor.Direction = DI_UP;
  10.   ItemStatus.LookedAt = true;
  11.   ChangeCaption();
  12.   actor.Talk("Interesting");
  13. }
  14.  
  15. // change caption
  16. function ChangeCaption()
  17. {
  18.   if(ItemStatus.LookedAt == true)
  19.   {
  20.     this.Caption = "Changed Item Name";
  21.   } else {
  22.     this.Caption = "Normal Item Name";
  23.   }
  24. }
  25.  
Title: Re: Change Item Caption after Interactions
Post by: Darky on August 07, 2009, 04:33:19 PM
Thank you, that pushed me into the right direction.

It could be possible the Player changes the Scene after looking at the item, so the new variable has to be defined as global in order to not loose the value.

Purely for completion for other users, this was my final code now:

Code: WME Script
  1. global MyItemNameStatus;
  2. ChangeCaption();
  3.  
  4. ////////////////////////////////////////////////////////////////////////////////
  5. on "LookAt"
  6. {
  7.         actor.GoToObject(this);
  8.         actor.Direction = DI_UP;
  9.        
  10.         MyItemNameStatus.LookedAt = true;
  11.         ChangeCaption();
  12.        
  13.         actor.Talk("Interesting");
  14. }
  15.  
  16. // change caption
  17. function ChangeCaption()
  18. {
  19.         if(MyItemNameStatus.LookedAt == true)
  20.         {
  21.                 this.Caption = "Changed Item Name";
  22.         } else {
  23.                 this.Caption = "Normal Item Name";
  24.         }
  25. }
  26.