Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Read book in inventory  (Read 3983 times)

0 Members and 1 Guest are viewing this topic.

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Read book in inventory
« on: November 13, 2013, 05:10:44 PM »

This probably has a simple solution but I'm stuck. I want the main character to pick up a medical record which will then be in inventory. The player should be able to click on the book and read it from the inventory. The record is a window which will be updated as information is discovered. My problem is that I can't figure out how to make something happen when an item is clicked in the inventory.

I think I need to alter the code in the game script after where it has:
    else if(Game.SelectedItem != null && Game.SelectedItem != ActObj)

I tried adding "&& Game.SelectedItem != "medRecord")" but that didn't work.  Any suggestions would be greatly appreciated.
 
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Read book in inventory
« Reply #1 on: November 13, 2013, 07:04:16 PM »

First, you need to add the LeftClick event in your item's script. By default, the scripts for the inventory items are placed in the "items" folder:

Code: WME Script
  1. on "LeftClick"
  2. {
  3.     //actor reads the book
  4. }
  5.  

Now, you changed the "else if" statement but with no result. This is because the game enters directly in the "if" statement. Try modifying the first "if" statement to add your code:

Code: WME Script
  1. if(ActObj.Type=="item" && Game.SelectedItem==null && Game.SelectedItem != "medRecord")
  2. {
  3.       Game.SelectedItem = ActObj;
  4. }
  5.  

This way, the code execution will end up in neither the "if", nor the "else if" but in the "else" statement below, which applies the left click event on the item.

If you plan to have more items that can be used with a simple click in the inventory, you should be careful not to end up with unreadable code, having to add all the item names in the if statement.
Logged

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Read book in inventory
« Reply #2 on: November 14, 2013, 09:24:18 PM »

That helped a lot.  It made me realize I was on the right track.

I have got the LeftClick set up in medRecord.script

I actually tried Game.SelectedItem != "medRecord" and ActObj != "medRecord" before trying it in the else if statement without success.

I went back and put some talk statements in various places to see where the flow was going. 

I don't think "if(ActObj.Type=="item" && Game.SelectedItem==null && Game.SelectedItem != "medRecord")" has the intended effect because if the Game.SelectedItem is null, then Game.SelectedItem can't be anything (including medRecord).

Anyway, the only time the "if" statement is skipped is when I have Game.SelectedItem == "medRecord" or ActObj == "medRecord".  Then the LeftClick in medRecords.script executes.

When the book is clicked in inventory, is it something other than the Game.SelectedItem or ActObj?  Or, do I have the medRecords item somehow set up incorrectly?

The item is identified on the screen as medRecords.  I checked the log and there aren't any errors so I don't think there is a typo.  It just isn't seeing the book as Game.SelectedItem or ActObj.

Any thoughts?

In item.items, I have:
ITEM
{
   CURSOR_COMBINED = TRUE
   CAPTION = "Medical Record"
   NAME = "medRecord"
   IMAGE = "items\book.bmp"
   CURSOR = "items\book.bmp"
   CURSOR_HOVER = "items\book_h.bmp"
   SCRIPT = "items\medRecord.script"
}
Logged

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Read book in inventory
« Reply #3 on: November 14, 2013, 11:52:05 PM »

I have it working now.

I went back to the WME Book Online.  In the downloadable bookgame, you find an old book in a drawer (which is the WME book).  You click on it to put it in inventory where it is clickable. Clicking it brings up some text but leaves the book in inventory, which is the behavior I was looking for.
In "if(ActObj!=null) ... "
I deleted "if(ActObj.Type=="item" && Game.SelectedItem == null)
{Game.SelectedItem = ActObj;}"

and started with "if(Game.SelectedItem != null && Game.SelectedItem!=ActObj)..."
   
The code pretty much follows the online example given in chapter 6 by Metamorphium.
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Read book in inventory
« Reply #4 on: November 15, 2013, 08:16:25 PM »

I am sorry for giving you an incomplete and not totally correct solution, but I saw that you were completely lost and tried to put you on the right track. Nevertheless, I am glad I helped.
Logged
 

Page created in 0.057 seconds with 20 queries.