Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Difficulty combining inventory items  (Read 7225 times)

0 Members and 1 Guest are viewing this topic.

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Difficulty combining inventory items
« on: June 25, 2015, 12:37:48 AM »

Hi,

I'm trying to follow the technique used in the WME book for combining items in the inventory.  I've got other items that work fine so I'm not sure what is wrong here.  This is a teaching app for veterinary students.

I have a dog, a syringe, and empty blood tubes in the inventory.  The idea is to click on the patient (the dog) with the syringe.  The syringe changes to a filled syringe.  That part works fine.  The next step is to click on the tubes with the syringe or click on the syringe with the tubes.  The tubes and syringe are deleted and filled blood tubes are now in the inventory. 

Here is the code in items:

Code: [Select]
ITEM
{
   CURSOR_COMBINED = TRUE
   CAPTION = "Filled Syringe"
   NAME = "syringeFull"
   IMAGE = "items\syringeFull.png"
   CURSOR = "items\syringeFull.sprite"
   CURSOR_HOVER = "items\syringeFull_h.png"
   SCRIPT = "items\syringeFull.script"
}

ITEM
{
   CURSOR_COMBINED = TRUE
   CAPTION = "Blood Tubes"
   NAME = "tubes"
   IMAGE = "items\tubes.png"
   CURSOR = "items\tubes.sprite"
   CURSOR_HOVER = "items\tubes_h.png"
   SCRIPT = "items\tubes.script"
}

ITEM
{
   CURSOR_COMBINED = TRUE
   CAPTION = "Filled Blood Tubes"
   NAME = "tubesFull"
   IMAGE = "items\tubesFull.png"
   CURSOR = "items\tubesFull.sprite"
   CURSOR_HOVER = "items\tubesFull_h.png"
   SCRIPT = "items\tubesFull.script"
}

And the code for the filled syringe:
Code: [Select]
////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  Game.SelectedItem = "syringeFull";
}

////////////////////////////////////////////////////////////////////////////////
on "tubes"
{
Game.Interactive = false;
actor.Talk("I'll fill these blood tubes");
Game.TakeItem("tubesFull");
Game.DeleteItem("tubes");
Game.Interactive = true;
Game.DeleteItem("syringeFull");
}

and finally, similar code for the empty tubes:
Code: [Select]
////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  Game.SelectedItem = "tubes";
}

on "syringeFull"
{
Game.Interactive = false;
actor.Talk("I'll fill these blood tubes");
Game.TakeItem("tubesFull");
Game.DeleteItem("syringeFull");
Game.Interactive = true;
Game.DeleteItem("tubes");
}

I have sprites for the filled syringe, the empty tubes and the filled tubes, all with the correct names.  I don't get any errors.  I see the text "use something with something" but nothing happens when I click.  Do I need to put anything in the scene?  I've deleted the sprites and recreated them without any success and I'm not sure what to try.

Any thoughts?
Logged

Dan Peach

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 100
    • View Profile
    • Viperante - Game Development
Re: Difficulty combining inventory items
« Reply #1 on: June 26, 2015, 01:22:42 AM »

Why is the LeftClick code in the item script? Shouldn't the LeftClick stuff be handled just in the main game.script?

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Difficulty combining inventory items
« Reply #2 on: June 26, 2015, 09:06:04 PM »

Thanks Dan.

I based the code on Metamorphium's WME book where the wire and and pliers were combined.  In the game code, I am using the method from the 3d demo project where if you hold down on the left key, the action menu pops up.  For now, I'm leaving the empty tubes on the table.  When you click on the empty tubes with the filled syringe from the inventory, the filled tubes are taken into the inventory and the syringe and empty tubes are deleted.

Now I have a similar problem.  I can click on the full container and filled tubes in the inventory and select them but I can't use them with anything.  What I want to do is go to the lab, click on the lab doctor to generate a report and delete the two items.  I use other items from the inventory on a different model in another scene so I tried using these on the lab doctor.  I didn't get what I expected.

I have
Code: [Select]
"on stethoscope"
{
    //do something
}

 for the dog in one room and the doctor in the other.  This is in the script for each of the 3D models in the 3D actors folders.  The player's character gets the stethoscope in the room where the dog is and then goes to the second room.  When the stethoscope is taken from the inventory and clicked on the doctor, the code for the dog model runs.


Is this expected?  Can you only click with an inventory item in the room where you get it or should I be looking for a problem in the game code?  Or am I putting "on stethoscope" in the wrong place?
Logged

Dan Peach

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 100
    • View Profile
    • Viperante - Game Development
Re: Difficulty combining inventory items
« Reply #3 on: June 26, 2015, 11:17:05 PM »

The problem must be in the game.script. Post that. :)

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Difficulty combining inventory items
« Reply #4 on: June 27, 2015, 12:22:38 AM »

Thanks.  That is what I thought too.  Our internet has been down - we're out in the country and can't get cable and there is a thunderstorm.  While off line, I copied the project to test.  I have an older version of the project that I tested first.  I put the male model in the examination room with the dog.  I can use the stethoscope with either one of them and get the correct response.

So then one by one, I did the following:
1. Copied the game.script to the new project.
2. Copied the gameloop.script to the new project.
3. The items.items code was identical.
4. Copied the stethoscope.script code (only minor changes there).
5. The model was the same since it wasn't in the old version - I just copied it in for testing.

I checked at each level but no change.

Lastly I tried copied the scene_init.script.  Still no change (except that everything was misplaced since the background has been changed).

Here is the game code but it is identical to the working version except that I commented out a model that is now added only to the scene.

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

//jah these are from actor 3d
global ClickStarted;
global ClickStartTime;
global ClickObject;

//jah from advice on disabling inventory
//still see in intro, not in menu
InventoryActive = true;

// store some of the game's attributes in global variables for convenience
Keyboard = Game.Keyboard;
Scene = Game.Scene;


// load the right-click menu
global WinMenu = Game.LoadWindow("interface\menu\menu.window");
WinMenu.Visible = false;

// load the "caption" window
var win = Game.LoadWindow("interface\system\caption.window");
global WinCaption = win.GetControl("caption");

global WinRecords = Game.LoadWindow("records/records.window");
WinRecords.Visible = false;

global MenuObject = null;

//jah load victor instead of trinity
//actor = Game.LoadActor3D("actors\trinity\trinity.act3d");
client = Game.LoadActor3D("actors\victor\victor.act3d");
vetM = Game.LoadActor3D("actors\vetM\vetM.act3d");
vetF = Game.LoadActor3D("actors\vetM\vetF.act3d");
patient = Game.LoadActor3D("actors\dudley\dudley.act3d");
//receptionist = Game.LoadActor3D("actors\vetM\receptionist.act3d");
actor = vetM;
Game.MainObject = actor;

//jah from tech demo load victor
// load our EmptyActor for inventory responces in the first persons scenes
//global EmptyActor;
EmptyActor = Game.LoadActor("actors\empty\empty.actor");
EmptyActor.SkipTo(400, 100);

//jah not sure about next object this might be inventory problem
//Game.InventoryObject = actor;

// run the "game loop" script
Game.AttachScript("scripts\game_loop.script");

//from testdemo for inventoryglob
// run the "Methods" script
Game.AttachScript("scripts\methods.script");

//jah not sure about this Game.InventoryVisible = true;
// which scene to load?
Game.ChangeScene(Game.StartupScene);

//metamorphium system_writer
writer = new Object("scripts\system_writer.script");
writer.Initialize();

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // what did we click?
  var ActObj = Game.ActiveObject;
  if(ActObj!=null)
  {
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");
  //jah from tech demo when actor not visible
  else if(actor.Active ==  false)
{
EmptyActor.Talk("I can't use these things together.");
}
  else actor.Talk("I can't use these things together.");

    }
    // just a simple click
    else ActObj.ApplyEvent("LeftClick");

  }
  // else propagate the LeftClick event to a scene
  else
  {
    Scene.ApplyEvent("LeftClick");
  }
}



////////////////////////////////////////////////////////////////////////////////
on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
    return;
  }

  var ActObj = Game.ActiveObject;

  // is the righ-click menu visible? hide it
  if(WinMenu.Visible == true) WinMenu.Visible = false;
  else if(ActObj!=null)
  {
    // if the clicked object can handle any of the "verbs", display the right-click menu
    if(ActObj.CanHandleEvent("Take") || ActObj.CanHandleEvent("Talk") || ActObj.CanHandleEvent("LookAt"))
    {
      // store the clicked object in a global variable MenuObject
      MenuObject = Game.ActiveObject;
      var Caption = WinMenu.GetControl("caption");
      Caption.Text = MenuObject.Caption;

      // adjust menu's position
      WinMenu.X = Game.MouseX - WinMenu.Width / 2;
      if(WinMenu.X < 0) WinMenu.X = 0;
      if(WinMenu.X+WinMenu.Width>Game.ScreenWidth) WinMenu.X = Game.ScreenWidth-WinMenu.Width;

      WinMenu.Y = Game.MouseY - WinMenu.Height / 2;
      if(WinMenu.Y<0) WinMenu.Y = 0;
      if(WinMenu.Y+WinMenu.Height>Game.ScreenHeight) WinMenu.Y = Game.ScreenHeight-WinMenu.Height;

      // and show the right-click menu
      WinMenu.Visible = true;

      // stop the actor from whatever he was going to do
      actor.Reset();
    }
    // no verbs supported, no menu is needed; just send the RightClick event to the object
    else ActObj.ApplyEvent("RightClick");
  }
}

//jah added left double click in case it is needed
//from tech demo
on "LeftDoubleClick"
{
  // what did we click?
  var ActObj = Game.ActiveObject;
  if(ActObj!=null)
  {
    // just a simple click
    ActObj.ApplyEvent("LeftDoubleClick");
  }

  // else propagate the LeftDoubleClick event to a scene
  else
  {
    Scene.ApplyEvent("LeftDoubleClick");
  }
}

////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  // on Esc or F1 key
  if(Keyboard.KeyCode==VK_ESCAPE || Keyboard.KeyCode==VK_F1)
  {
    // load and display the main menu window
    WinCaption.Visible = false;
    var WinMainMenu = Game.LoadWindow("interface\system\mainmenu.window");
    WinMainMenu.Center();
    WinMainMenu.GoSystemExclusive();
    Game.UnloadObject(WinMainMenu);
  }
}


////////////////////////////////////////////////////////////////////////////////
on "QuitGame"
{
  // on Alt+F4 (window close)
  // load and display the quit confirmation window
  if(QuestionBox("Do you really want to quit?")) Game.QuitGame();
}


////////////////////////////////////////////////////////////////////////////////
method QuestionBox(Message, SystemExclusive)
{
if(SystemExclusive==null) SystemExclusive = true;

var Window = Game.LoadWindow("interface\system\question.window");
Window.Center();
Window.xMessage = Game.ExpandString(Message);

if(SystemExclusive) Window.GoSystemExclusive();
else Window.GoExclusive();

var Result = Window.xResult;
Game.UnloadObject(Window);

return Result;
}

I'm going to try moving the entire scene from the old game into the new one to see if there is anything there.  I completely recreated that scene.  After that I'm out of ideas.

Thanks again!
Logged

Dan Peach

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 100
    • View Profile
    • Viperante - Game Development
Re: Difficulty combining inventory items
« Reply #5 on: June 27, 2015, 01:43:49 AM »

Hmmm, well, first of all it's on "stethoscope" - only the item is in the quotation.

Second of all, errr, I dunno. :D I'm no expert. And I haven't done anything with 3D actors.

What's the methods.script?

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Difficulty combining inventory items
« Reply #6 on: June 27, 2015, 02:45:09 AM »

It should be on "stethoscope", kind of like on "LeftClick".  The methods.script has some additional methods - it was suggested in the test3d demo with Victor from DREAMWEB. It is a really helpful tutorial for 3d actors.  It is still available - just search for dreamweb for the link.

Meanwhile, I tried going forwards from the old program.  I changed the game and game loop scripts to the new code and copied the new scene to the old program.  I had to make some changes to the script for the model and things are working okay.  So the problem isn't with the game and gameloop scripts.  For now, I'll probably just have the lab doctor tell the main character to place the samples on the table.  When the main actor exists, the sample will be deleted and a report will go into the record.  When I have time, I'll keep working on replacing code in the first version.  I've made a lot of changes so it will take a while.

Thanks for your help!  If you think of anything else to try ...

Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Difficulty combining inventory items
« Reply #7 on: June 28, 2015, 05:59:17 PM »

binary1, I think you need to tell us again what is your problem. You said you solved the first issue with the blood tubes but now you are stuck again. If you solved that one then the solution to your issues should be straightforward. But please re-write your issue and show us your updated code. Combining items is quite straightforward and it is good for you to learn the process because you will be doing it a lot.
Logged

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Difficulty combining inventory items
« Reply #8 on: July 03, 2015, 06:16:10 AM »

Hello Anarchist,
Thanks for your response.  I was actually already combining two inventory items without any problem so I couldn't figure out what was going wrong.  I posted the code that I had in the first posting.

Here is the situation.  I have a dog, an empty syringe, and empty tubes in inventory.  I click on the dog with the empty syringe which causes the empty syringe to be be deleted and a filled syringe to appear in inventory.  (It never occurred to me to click the syringe with the dog. That would be a bit awkward.)  Then I wanted to fill the tubes using the filled syringe.  That is the part that wouldn't work.

I am using the action menu that was in the 3D demo.  If the left mouse button is held down, the action menu appears.  In the initial script that I had, I only implemented on "LeftClick" for both objects, on "tubes" for the syringe and on "filledSyringe" for the tubes.  I think that what happens is that whichever item is clicked becomes the game selected item.  on "tubes" and on "filledSyringe" never run.

The first solution was just to leave the empty tubes on the counter, never take them into inventory and click on them with the filled syringe.  But that left me with similar problems elsewhere. 

The best solution was to implement on "Take" for the empty tubes and filled syringe.  For the filled syringe I have on "LeftClick" and on "tubes" as in my first posting below.  For the tubes, I have on "LeftClick" and on "filledSyringe" as in my first posting below.  I also have on "Take" for both objects, which is the same as the on "LeftClick" method.  The one for the filled syringe is as follows:
Code: [Select]
on "Take"
{
  Game.SelectedItem = "syringeFull";
}

Everything now runs correctly.  I think the problem only occurs when the left click action menu is used, not a right click menu. 
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Difficulty combining inventory items
« Reply #9 on: July 03, 2015, 10:52:10 PM »

Hello binary1,

So when you switched from the left click menu to the right click one the problem was solved?

Check the following code in the game.script you posted:

Code: WME Script
  1. // what did we click?
  2.   var ActObj = Game.ActiveObject;
  3.   if(ActObj!=null)
  4.   {
  5.         if(Game.SelectedItem != null && Game.SelectedItem!=ActObj)
  6.     {
  7.           var Item = Game.SelectedItem;
  8.           if(ActObj.CanHandleEvent(Item.Name)) ActObj.ApplyEvent(Item.Name);
  9.  

ActObj is whatever you clicked on; in your case you clicked syringeFull on tubes, therefore ActObj is the tubes item.
Game.SelectedItem is the item you have selected, in your case syringeFull.

The combination of the items takes place here:

Code: WME Script
  1.  

If tubes item has on "syringeFull" in it's script, ActObj.CanHandleEvent(Item.Name) is true therefore ActObj.ApplyEvent(Item.Name) is executed, which runs whatever code you have in on "syringeFull".

The 3D demo works a bit differently. In game.script there is on "LeftClick" and on "LeftRelease". The code that handles item combination is in on "LeftRelease". It should work though. When you click synringeFull on tubes, on "syringFull" event handler should run.

Anyway, I prefer the right click action menu, so go with that   :D
Logged
 

Page created in 0.083 seconds with 25 queries.