Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Marek on June 01, 2004, 12:53:54 PM

Title: Undefined method 'CanHandleEvent'
Post by: Marek on June 01, 2004, 12:53:54 PM
Sorry for temporarily taking over the forums with the last few topics ::)

I have a little bug that I can't figure out:

13:50: Runtime error. Script 'scripts\game.script', line 44
13:50:   Call to undefined method 'CanHandleEvent'. Ignored.

I changed the interface so that it doesn't use the coin, but instead only has two verbs: LookAt (left clicks) and Action (right clicks). It's all in game.script now, not in inventory.script.

Quote
////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // what did we click?
  var ActObj = Game.ActiveObject;
 
  // if there's an inventory item selected, deselect it
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
    return; }

  // if there's no inventory item selected, but the cursor is hovering above an object, apply the LookAt verb
  else if(ActObj!=null && ActObj.CanHandleEvent("LookAt"))
  {
    ActObj.ApplyEvent("LookAt");
  }   

  // else propagate the LeftClick event to a scene
  else
  {
    Scene.ApplyEvent("LeftClick");
  }
}

Any idea why I can't use CanHandleEvent in this context?
The error occurs when left clicking on the floor, not when clicking on objects.
Title: Re: Undefined method 'CanHandleEvent'
Post by: Mnemonic on June 01, 2004, 01:05:45 PM
I suppose it happens when the ActObj is null.
Try to break the condition into something like:

if(ActObj!=null)
{
Title: Re: Undefined method 'CanHandleEvent'
Post by: Marek on June 01, 2004, 01:36:09 PM
Yeah, I actually tried that already ... but then my character would only walk along a thin slice of my floor region (like the top 1/5th of the space), so I quickly put it back the way it was. :o
Title: Re: Undefined method 'CanHandleEvent'
Post by: Mnemonic on June 01, 2004, 01:47:13 PM
Yeah, I actually tried that already ... but then my character would only walk along a thin slice of my floor region (like the top 1/5th of the space), so I quickly put it back the way it was. :o

Are you sure? Did you do something like:

Code: [Select]
  else if(ActObj!=null)
  {
    if(ActObj.CanHandleEvent("LookAt")) ActObj.ApplyEvent("LookAt");
  }   
  // else propagate the LeftClick event to a scene
  else
  {
    Scene.ApplyEvent("LeftClick");
  }
}
Title: Re: Undefined method 'CanHandleEvent'
Post by: Marek on June 01, 2004, 02:28:31 PM
Erm yeah, more or less:

Quote
  // if there's no inventory item selected, but the cursor is hovering above an object, apply the LookAt verb
  else if(ActObj!=null)
  {
    if(ActObj.CanHandleEvent("LookAt")) ActObj.ApplyEvent("LookAt");

    // if (ActObj.CanHandleEvent("LookAt")) {
    // ActObj.ApplyEvent("LookAt"); }
  }   

  // else propagate the LeftClick event to a scene
  else
  {
    Scene.ApplyEvent("LeftClick");
  }

The character still refuses to walk where he is supposed to. I can't understand why he can only walk in certain places when the code is like this. There's nothing that corresponds with the area that suddenly seems to be blocked. There are no decoration regions or region sprites on the part where he can't walk.

Actually let me just give you the larger context here:
Quote
////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // what did we click?
  var ActObj = Game.ActiveObject;
 
  // if there's an inventory item selected, deselect it
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
    return; }

  // if there's no inventory item selected, but the cursor is hovering above an object, apply the LookAt verb
  else if(ActObj!=null)
  {
    if(ActObj.CanHandleEvent("LookAt")) ActObj.ApplyEvent("LookAt");

    // if (ActObj.CanHandleEvent("LookAt")) {
    // ActObj.ApplyEvent("LookAt"); }
  }   

  // else propagate the LeftClick event to a scene
  else
  {
    Scene.ApplyEvent("LeftClick");
  }
}


////////////////////////////////////////////////////////////////////////////////
on "RightClick"
{
  // what did we click?
  var ActObj = Game.ActiveObject;
  if(ActObj!=null)
  {
    // using an inventory item on another object
    if(Game.SelectedItem != null && Game.SelectedItem!=ActObj)
    {
      var Item = Game.SelectedItem;
      if(ActObj.CanHandleEvent(Item.Name)) ActObj.ApplyEvent(Item.Name);
      else if(Item.CanHandleEvent("default-use")) Item.ApplyEvent("default-use");
      else if(ActObj.CanHandleEvent("default-use")) ActObj.ApplyEvent("default-use");
      else actor.Talk("I can't use these things together.");
    }

    // clicking an inventory item
    else if(ActObj.Type=="item" && Game.SelectedItem==null)
    {
      Game.SelectedItem = ActObj;
    }
    // just a simple click
    else {

    if(ActObj.CanHandleEvent("Action")) ActObj.ApplyEvent("Action");
   }
  }
  // else propagate the RightClick event to a scene
  else
  {
    Scene.ApplyEvent("RightClick");
  }
}
Title: Re: Undefined method 'CanHandleEvent'
Post by: Mnemonic on June 01, 2004, 02:33:31 PM
Ok, I believe the problem is that the background entity of your scene has the "Interactive" flag turned on, right?
So, either turn it off or change the code to comething like:

Code: [Select]
  else if(ActObj!=null)
  {
    if(ActObj.CanHandleEvent("LookAt")) ActObj.ApplyEvent("LookAt");
    else Scene.ApplyEvent("LeftClick");
  }   
  // else propagate the LeftClick event to a scene
  else
  {
    Scene.ApplyEvent("LeftClick");
  }
}

This way all the clicks not handled by the LookAt event get routed to the scene.
Title: Re: Undefined method 'CanHandleEvent'
Post by: Marek on June 01, 2004, 03:52:26 PM
That did the trick. Muchos gracias senior.
Title: Re: Undefined method 'CanHandleEvent'
Post by: McCoy on June 01, 2004, 06:43:14 PM
hhm... it's "Muchas", not "Muchos" in "Muchas gracias se
Title: Re: Undefined method 'CanHandleEvent'
Post by: Marek on June 01, 2004, 07:41:28 PM
Google says:
874,000 for Muchos gracias
1,050,000 for Muchas gracias

I saw the muchos spelling so much I assumed it was the right one. Heh. ::)
Title: Re: Undefined method 'CanHandleEvent'
Post by: McCoy on June 01, 2004, 09:36:20 PM
Well, "gracias" is fem
Title: Re: Undefined method 'CanHandleEvent'
Post by: Mnemonic on June 02, 2004, 08:29:23 AM
WHAT A DUMB DISCUSSION!!! LOL

One always learns new things in here...  ;D