Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Undefined method 'CanHandleEvent'  (Read 6033 times)

0 Members and 1 Guest are viewing this topic.

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Undefined method 'CanHandleEvent'
« 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.
Logged

Mnemonic

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

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Undefined method 'CanHandleEvent'
« Reply #2 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
Logged

Mnemonic

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

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Undefined method 'CanHandleEvent'
« Reply #4 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");
  }
}
Logged

Mnemonic

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

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Undefined method 'CanHandleEvent'
« Reply #6 on: June 01, 2004, 03:52:26 PM »

That did the trick. Muchos gracias senior.
Logged

McCoy

  • The cocido eater
  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 365
  • Spurrrrrrring
    • View Profile
    • Spur Games
Re: Undefined method 'CanHandleEvent'
« Reply #7 on: June 01, 2004, 06:43:14 PM »

hhm... it's "Muchas", not "Muchos" in "Muchas gracias se
Logged

Click here to sign my sig!

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Undefined method 'CanHandleEvent'
« Reply #8 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. ::)
Logged

McCoy

  • The cocido eater
  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 365
  • Spurrrrrrring
    • View Profile
    • Spur Games
Re: Undefined method 'CanHandleEvent'
« Reply #9 on: June 01, 2004, 09:36:20 PM »

Well, "gracias" is fem
Logged

Click here to sign my sig!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Undefined method 'CanHandleEvent'
« Reply #10 on: June 02, 2004, 08:29:23 AM »

WHAT A DUMB DISCUSSION!!! LOL

One always learns new things in here...  ;D
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.02 seconds with 20 queries.