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: Item cursor only on certain objects  (Read 4721 times)

0 Members and 1 Guest are viewing this topic.

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Item cursor only on certain objects
« on: February 14, 2006, 01:25:17 AM »

Hi all,

I want to have a glowing item cursor for each item, which only gets displayed when any particular item is over an object with which it can be used. So, say I have a key and a door and a window, putting the key over the door gives us the glowing key, but putting the key over the window just gives us the normal key - so then you know to use the key on the door.

Is that already easily possible easily somehow? I don't think I can find anything that relates to using items only on specific other items.

Thanks.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Item cursor only on certain objects
« Reply #1 on: February 14, 2006, 09:20:22 AM »

There's no direct support for this, but it has been successfuly scripted in certain unannounced WME game. The idea was to handle the MouseEntry event of a given scene entity, check which inventory item is currently selected, and set the entity's cursor (using SetCursor()) appropriately.

I don't have the exact code here with me, but very roughly it would look like this (totally untested):

Quote
on "MouseEntry"
{
  // no item selected, reset cursor to default
  var ItemName = Game.SelectedItem;
  if(ItemName==null)
  {
    this.SetCursor(null);
    return;
  }
  // get the item object, so that we can read it's cursor images
  var Item = Game.GetItem(ItemName);

  // if the entity can handle this item, set the item's hover cursor
  if(this.CanHandleEvent(ItemName)) this.SetCursor(Item.GetHoverCursor());
  // else set item's normal cursor
  else this.SetCursor(Item.GetNormalCursor());
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Item cursor only on certain objects
« Reply #2 on: February 14, 2006, 09:27:17 AM »

Thanks - seems like it should work - the "CanHandleEvent" thing confuses me though - what does that mean exactly?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Item cursor only on certain objects
« Reply #3 on: February 14, 2006, 09:32:07 AM »

Basically it checks if the entity's script contains the on "something" ... block, i.e. an event handler for a specified event name.

For example, if the script contains

on "LeftClick"
{
  // some code
}

Then CanHandleEvent("LeftClick") will return true, because the entity is capable of handling the "LeftClick" event.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Item cursor only on certain objects
« Reply #4 on: February 14, 2006, 09:58:15 AM »

ahhh ok I get it - thanks.

This code doesn't work though - I'm assuming you would have to put this code on every scene entity that could be interacted with...? I tried it on two, one which could handle the event and the other not, but both just showed the hover cursor.

And, if I rightclick on the entity that can handle the event, to get rid of the hover cursor and send the item back to the ivnentory, the cursor changed to another inventory items cursor. Then, moving the mouse off the entity, the new cursor went back to the inventory, BUT, next time I went over that entity just with the normal mouse cursor, it showed the second inventory item again really quickly before the hover mouse cursor.

Hope all that made sene. ???   ;D
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Item cursor only on certain objects
« Reply #5 on: February 14, 2006, 01:13:26 PM »

The right-click will have to be handled separately in game.script. There's a piece of code which handles right-click and deselects an item. You'd have to add one line which sets default cursor to Game.ActiveObject when deselecting an item.
As for why the script above doesn't work, I don't know, I'd have to try it. The principle should be right, so there's probably some stupid mistake.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Item cursor only on certain objects
« Reply #6 on: February 14, 2006, 02:38:29 PM »

Thanks - I'll play around.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Item cursor only on certain objects
« Reply #7 on: February 14, 2006, 10:07:34 PM »

Ok, I realized it's not that easy, because the item hover cursor overrides the cursor assigned to an entity. I'm not saying it wouldn't be possible to script it, but it would require scripting the sprites themselves, so I think I'll add this functionality directly to the engine, so that the engine checks automatically if the entity can respond to the selected item and it will display the appropriate cursor.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Item cursor only on certain objects
« Reply #8 on: February 14, 2006, 10:51:12 PM »

That's great.  ;D

I look forward to it.
Logged

rkitting

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 44
    • View Profile
Re: Item cursor only on certain objects
« Reply #9 on: July 17, 2008, 02:56:43 PM »

Has this feature been added? Been trying to do this the last few hours.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Item cursor only on certain objects
« Reply #10 on: July 17, 2008, 02:58:59 PM »

Yes, added as Game.SmartItemCursor.
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.066 seconds with 24 queries.