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: Stop inventory item from being selected  (Read 3773 times)

0 Members and 1 Guest are viewing this topic.

Squinage

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
    • Re:Gamed
Stop inventory item from being selected
« on: September 21, 2012, 11:41:25 AM »

I have yet another inventory question (sorry). I have tried searching the forum, but it's quite hard to search for.

I basically just want to make an item in the inventory "unselectable". I have an item you can pick up and read (a note), but I don't want the player to be able to select it is an item to be used with other objects.

Any help on how to do this would be great.

Squin
Logged

lof

  • Lurker
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 19
  • A Leap Of Fate
    • View Profile
Re: Stop inventory item from being selected
« Reply #1 on: September 21, 2012, 03:05:58 PM »

open Game.Script

search for and add the underlined text into your script (replace itemname with your itemname):

on "LeftClick"
{
  // what did we click?
  var ActObj = Game.ActiveObject;
  if(ActObj!=null)
  //~ if(ActObj!=null && ActObj)
  {
    // clicking an inventory item
    if(ActObj.Type=="item" && Game.SelectedItem==null && ActObj.Name != "itemname")
    {
      Game.SelectedItem = ActObj;
    }

do the same for: on "LeftDoubleClick"

that will cancel left clicking on this item.
Logged

Squinage

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
    • Re:Gamed
Re: Stop inventory item from being selected
« Reply #2 on: September 21, 2012, 04:25:18 PM »

Thank you for the reply. That works great.

I wondered if there was another way of implementing this? The reason I ask is that if you had multiple object that you didn't want to be selected, this section of the code could get quite cumbersome. Is there a way of defining a list of items?

Squin
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Stop inventory item from being selected
« Reply #3 on: September 21, 2012, 04:29:35 PM »

I'm sure there are many ways to do that. You can add any custom properties to your game objects. So for example, in your item's script you would do:

Code: WME Script
  1. this.Unclickable = true;
  2.  

And the condition above would now look like this:

Code: WME Script
  1. if(ActObj.Type=="item" && Game.SelectedItem==null && ActObj.Unclickable != true)
  2.  

So all items that set this property will become "unclickable".
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Squinage

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
    • Re:Gamed
Re: Stop inventory item from being selected
« Reply #4 on: September 21, 2012, 05:30:13 PM »

Thanks to lof for providing an immediate workaround, but I think Mnemonic's solution is a bit smoother.

Either way, thanks for the help guys.

Squin
« Last Edit: September 21, 2012, 05:33:51 PM by Squinage »
Logged

lof

  • Lurker
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 19
  • A Leap Of Fate
    • View Profile
Re: Stop inventory item from being selected
« Reply #5 on: September 21, 2012, 06:44:57 PM »

you mentioned you needed it for one specific item :)
nevermind, you're welcome.
Logged
 

Page created in 0.036 seconds with 21 queries.