Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Change Item Caption after Interactions  (Read 2665 times)

0 Members and 1 Guest are viewing this topic.

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Change Item Caption after Interactions
« 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";
}
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Change Item Caption after Interactions
« Reply #1 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.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: Change Item Caption after Interactions
« Reply #2 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.  
Logged
 

Page created in 0.024 seconds with 24 queries.