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: Using two (inside inventory) items, and changing for new one  (Read 6782 times)

0 Members and 1 Guest are viewing this topic.

helios

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 41
    • View Profile
Using two (inside inventory) items, and changing for new one
« on: January 15, 2007, 03:42:29 PM »

Hi,

I´ve looked for solution to those problems and could not find. As I am running out of time, here I am again.

The point is, I have two items, already inside inventory, and need to use item A with item B. Ok, I got item B file and wrote on "A". It needs to change item B from (example) "emptyGlass" to "filledGlass", but "filledGlass" is not in the game untill now, and this action can go on any scene.

What is best to make this object B (emptyGlass) to become a filled glass? Do I create two objects or change glass object state and image from empty to filled? If two objects is better, is better having this filled glass only defined and not inside a scene? Put it inside a scene and make it invisible?

Is there a different way to use object A with B when inside the inventory or it works like it was outside inventory?

Thanks a lot,
Helios

Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Using two (inside inventory) items, and changing for new one
« Reply #1 on: January 15, 2007, 04:21:02 PM »

Both approaches are possible, but I think it's better to make two separate inventory items. That way they can use different names, different script etc. So simply take the new item and delet the old item.

Game.TakeItem("filledGlass");
Game.DeleteItem("emptyGlass");

No need to do any changes in the scene.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

helios

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 41
    • View Profile
Re: Using two (inside inventory) items, and changing for new one
« Reply #2 on: January 15, 2007, 06:03:50 PM »

Not working.

I have two items: lamparina and garrafa

When both are in the inventory, I try using garrafa on lamparina and they just change positions (lamparina comes to the mouse pointer and garrafa goes back to the inventory).

The codes are this way:

items.items:
Code: [Select]
ITEM
{
  CURSOR_COMBINED = TRUE
  CAPTION = "Garrafa de Whisky"
  NAME = "garrafa"
  IMAGE = "items\garrafa.png"
  CURSOR = "items\garrafa.png"
  CURSOR_HOVER = "items\garrafa_h.png"
  CURSOR_COMBINED = FALSE;
  SCRIPT = "items\garrafa.script"
}

ITEM
{
  CURSOR_COMBINED = TRUE
  CAPTION = "Lamparina"
  NAME = "lamparina"
  IMAGE = "items\lamparina.png"
  CURSOR = "items\lamparina.png"
  CURSOR_HOVER = "items\lamparina_h.png"
  CURSOR_COMBINED = FALSE;
  SCRIPT = "items\lamparina.script"
}

ITEM
{
  CURSOR_COMBINED = TRUE
  CAPTION = "Lamparina"
  NAME = "lamparinaAcesa"
  IMAGE = "items\lamparinaAcesa.png"
  CURSOR = "items\lamparinaAcesa.png"
  CURSOR_HOVER = "items\lamparinaAcesa_h.png"
  CURSOR_COMBINED = FALSE;
  SCRIPT = "items\lamparinaAcesa.script"
}

garrafa.script
Code: [Select]
#include "scripts\base.inc"

////////////////////////////////////////////////////////////////////////////////
on "LeftClick" {
  Game.SelectedItem = "garrafa";
}

lamparina.script
Code: [Select]
#include "scripts\base.inc"

////////////////////////////////////////////////////////////////////////////////
on "LeftClick" {
  Game.SelectedItem = "lamparina";
}

////////////////////////////////////////////////////////////////////////////////
on "garrafa" {
  //this Talk I included after not working, to see if at least it works, but it DIDNT
  actor.Talk("should at least this line work?");
  Game.TakeItem("lamparinaAcesa"); //lamparinaAcesa is not included in any scene
  Game.DeleteItem("lamparina");
}


lamparinaAcesa.script
Code: [Select]
#include "scripts\base.inc"

////////////////////////////////////////////////////////////////////////////////
on "LeftClick" {
  Game.SelectedItem = "lamparinaAcesa";
}

What should be wrong here?
« Last Edit: January 15, 2007, 06:52:29 PM by helios »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Using two (inside inventory) items, and changing for new one
« Reply #3 on: January 15, 2007, 07:14:46 PM »

I don't know, looks good to me... So you mean the on "garrafa" {} handler isn't called at all?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

helios

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 41
    • View Profile
Re: Using two (inside inventory) items, and changing for new one
« Reply #4 on: January 15, 2007, 07:17:54 PM »

Yeah, and I tried with other two objects, just adding a Talk method to test, and didn´t work too.
What else has something to do with it in my code that I could show?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Using two (inside inventory) items, and changing for new one
« Reply #5 on: January 15, 2007, 07:21:53 PM »

Did you make any changes to the on "LeftClick" {} handler in game.script?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

helios

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 41
    • View Profile
Re: Using two (inside inventory) items, and changing for new one
« Reply #6 on: January 15, 2007, 07:35:34 PM »

Yeah, I just used it like demo3d, so I call the verbs menu by holding left button pressed. But this is not a problem when I use an item in inventory with another outside. In those, everything works fine.
The problem only exists when both items are in the inventory.

Code: [Select]
////////////////////////////////////////////////////////////////////////////////
on "LeftClick" {
  // no object selected, apply click to scene
  if(Game.ActiveObject==null)   {
    Scene.ApplyEvent("LeftClick");
    return;
  }

  // perform click start
  ClickObject = Game.ActiveObject;

  // do we need to show the verb window at all?   
  if(!ClickObject.CanHandleEvent("LookAt") && !ClickObject.CanHandleEvent("Talk") &&
     !ClickObject.CanHandleEvent("Take")) {
  // nah, just click it
  //Game.Msg(ClickObject.Name);
    ClickObject.ApplyEvent("LeftClick");
    ClickStarted = false;
    ClickObject = null;
  }
  else {
    // mark click start and remember the time
    ClickStarted = true;
    ClickStartTime = Game.CurrentTime;
  }
}

////////////////////////////////////////////////////////////////////////////////
on "LeftRelease" {

  // 'obj' is actually the verb button the mouse was over when we released the left button
  var obj = Game.ActiveObject;
  ClickStarted = false;
 
  // we are leaving the verbs window, handle the selected verb
  if (WinVerbs.Visible) {

    // hide the window
    WinVerbs.Visible = false;
   
    // this is necessary, because we can left-click earlier than this stuff finishes
    var TempClickObj = ClickObject;
    ClickObject = null;

    // apply the verb if the object can handle it
    if (TempClickObj.CanHandleEvent(obj.Name)) {
      TempClickObj.ApplyEvent(obj.Name);
    } else {
      // otherwise use default event handling
      if (obj.Name=="LookAt") {
        actor.Talk("Looks nice.");
      } else if (obj.Name=="Talk") {
        actor.Talk("Hello...");
      } else if (obj.Name=="Take") {
         actor.Talk("I won't pick that up.");
      }
    }
  }
 
  // verbcoin is NOT visible, i.e. we go for a normal click
  else if (Game.ValidObject(ClickObject)) {

    // did we click using an inventory item?
    if (Game.SelectedItem != null && Game.SelectedItem!=ClickObject) {

      var item = Game.SelectedItem;
      if (ClickObject.CanHandleEvent(item.Name)) {
        ClickObject.ApplyEvent(item.Name);
      } else {
        // default use handlers, same as in WME demo
        if (item.CanHandleEvent("default-use")) {
          item.ApplyEvent("default-use");
        } else if (ClickObject.CanHandleEvent("default-use")) {
          ClickObject.ApplyEvent("default-use");
        } else {
          ClickObject = null;
          actor.Talk("I can't use these things together.");
        }
      }
    }
    // perform normal click
    else ClickObject.ApplyEvent("LeftClick");
    ClickObject = null;
  }
}
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Using two (inside inventory) items, and changing for new one
« Reply #7 on: January 15, 2007, 07:51:36 PM »

Hm, I still can't see anything wrong with the code (but then again, I'm falling asleep right now..). Could you make some minimal testing project for me, with just one scene, the inventory items and the global scripts?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

helios

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 41
    • View Profile
Re: Using two (inside inventory) items, and changing for new one
« Reply #8 on: January 15, 2007, 07:54:20 PM »

Sure.
I´ll do it and post in some minutes. Go sleep and look when you are ok.  ;)

Thanks
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Using two (inside inventory) items, and changing for new one
« Reply #9 on: January 16, 2007, 01:27:44 AM »

  // did we click using an inventory item?
    if (Game.SelectedItem != null && Game.SelectedItem!=ClickObject) {

      var item = Game.SelectedItem;
      if (ClickObject.CanHandleEvent(item.Name)) {
        ClickObject.ApplyEvent(item.Name);
      } else {

To this block in game.script put some Game.Msg to see what's going on.

like this for example:
    if (Game.SelectedItem != null && Game.SelectedItem!=ClickObject) {

      var item = Game.SelectedItem;
      Game.Msg(item.Name);
      if (ClickObject.CanHandleEvent(item.Name)) {
        Game.Msg("Event is applied, so what's up?");
        ClickObject.ApplyEvent(item.Name);
      } else {
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

helios

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 41
    • View Profile
Re: Using two (inside inventory) items, and changing for new one
« Reply #10 on: January 17, 2007, 03:47:57 AM »

Hi,

I had problems with my computer and could not send it before.
I made a scene with all the objects needed (http://www.heliospb.net/_santosDumont/ConspiracaoDumontv2.0.rar). Just get the saw (serra) and use it with the oil-lamp (lamparina), what adds the second to the inventory. Already in there is the whisky bottle (garrafa) that is the one used with oil-lamp that has to delete this oil-lamp and load a lighted oil-lamp (lamparinaAcesa), what doesn´t happen.

Metamorphium said something really interesting. I used that Game.Msg and it shows, for example, the saw (serra) name when it´s used with the oil-lamp, or in the horse, but if I try with another object inside the inventory, the name (printed by Game.Msg) doesn´t appear.

Thanks,
Helios
Logged

helios

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 41
    • View Profile
Re: Using two (inside inventory) items, and changing for new one
« Reply #11 on: January 17, 2007, 03:51:55 AM »

Also, I am having problems with Caption inside verbs window. It doenst change the Caption word to the Caption var of each object, but it works when the mouse pointer is over the object. Weird.

And I can´t figure out how to only hide the inventory when the mouse leave it´s area. I looked for the code, but nothing worked.

Thanks. Gotta finish my project before jan 31st, that´s why I am asking so many (but never before trying many times first).
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Using two (inside inventory) items, and changing for new one
« Reply #12 on: January 17, 2007, 08:48:40 AM »

1. the mystery is solved:

look at the following condition in game.script (LeftClick):

Code: [Select]
  if(!ClickObject.CanHandleEvent("LookAt") && !ClickObject.CanHandleEvent("Talk") &&
     !ClickObject.CanHandleEvent("Take")) {
  // nah, just click it
  //Game.Msg(ClickObject.Name);
    ClickObject.ApplyEvent("LeftClick");
    ClickStarted = false;
    ClickObject = null;
  }

Now your item handling is in on "LeftRelease" which occurs obviously after LeftClick. So you click on an object and if it doesn't have
any of the following events defined, it will simply set ClickObject to null and ClickStarted to false, so LeftRelease will never get triggered.
So basically you are throwing away all inter inventory interactions for items (in this case items\lamparina.script) which doesn't have at least one of those three events defined. So you should consider rewriting this code a bit if you want to see it working.

2. I have to catch the bus so I'll answer later if this will be still relevant. :)


Edit: just to be more precise:   else if (Game.ValidObject(ClickObject)) {
this throws the LeftRelease of the track since you previously set the ClickObject to null :)
« Last Edit: January 17, 2007, 08:50:17 AM by metamorphium »
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Using two (inside inventory) items, and changing for new one
« Reply #13 on: January 17, 2007, 06:39:59 PM »

Also, I am having problems with Caption inside verbs window. It doenst change the Caption word to the Caption var of each object, but it works when the mouse pointer is over the object. Weird.
Well in your game_daemon.script there's:

Code: [Select]
WinVerbs.Caption = ClickObject.theCaption;
Which doesn't really do anything. Just copy the code from WME demo 3D and it should work:

Code: [Select]
var Caption = WinVerbs.GetWidget("caption");
Caption.Text = ClickObject.Caption;


And I can´t figure out how to only hide the inventory when the mouse leave it´s area. I looked for the code, but nothing worked.
Again, see the WME Demo 3D. It checks the mouse position and shows/hides the inventory. You'll have to make a little more complex check to see if the mouse is inside the inventory window rectangle or not.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

helios

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 41
    • View Profile
Re: Using two (inside inventory) items, and changing for new one
« Reply #14 on: January 17, 2007, 07:59:01 PM »

metamorphium,

You´re right about the problem with the items in inventory! The problem was there and I used a var to check if there´s an item being used on click.
Worked perfectly,
Thanks!

Mnemonic,
Thanks for the help with those small but important (cause I had problems finding where) points, thanks a lot!

Getting back to work!
« Last Edit: January 17, 2007, 08:03:41 PM by helios »
Logged
 

Page created in 0.115 seconds with 24 queries.