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: ITEM WITH SPRITE  (Read 5431 times)

0 Members and 1 Guest are viewing this topic.

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
ITEM WITH SPRITE
« on: April 09, 2013, 10:52:24 PM »

Hello,

Could someone help?

 I was wandering how you use an item from the inventory with scene sprite? So you select your item, use it with scene sprite, animation happens, item vanishes from inventory?

Thanks,
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: ITEM WITH SPRITE
« Reply #1 on: April 10, 2013, 06:36:41 AM »

It does whatever you tell it to do  ;)

To see what code is executed when you combine an inventory item with a scene entity (be it sprite or region entity) you need to check the script game.script and more specifically the "LeftClick" event.

In the default game.script LeftClick event first assigns the active object to a variable. The active object is the interactive object you clicked on. If you did not click an interactive object then it will be null. The other important game variable is the selected item, which will be your inventory item (or null if none selected). Then the script will look for an event inside the entity you clicked on named like your item (if you have an item "book" selected it will look for an on "book" event).

If you wish for the item to disappear from the inventory you need to define it inside the entity on "item" code, calling Game.DropItem("itemname").
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: ITEM WITH SPRITE
« Reply #2 on: April 11, 2013, 09:59:38 PM »

Hello again anarchist!

Yey, I managed to get to get an item to work with a scene object! But......   when I placed the game.dropitem at the end of the on "objectname" the inventory item vanished as desired and the animation in the scene played but then it crashed the level.

Once the scene object dropped the item, my cursor turns to a loading egg timer and all the scene interaction with mouse stops and I have to quit the game. Have I missed something in my script or is there a limitation that I am unaware of?

Thanks,

Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: ITEM WITH SPRITE
« Reply #3 on: April 12, 2013, 04:40:21 PM »

Hello again dude

It could be anything. It is hard to guess without looking at your code. Generally speaking, when you have code bugs it is better to show us the code you believe causes the problem so we can better understand where you go wrong, and perhaps some screenshots (if you notice that we don't understand what the problem is). Ideally, you could provide a sample project that reproduces the issue.

If I had to make a guess, judging by what you say, I would say the animation is guilty, or the code you have after the animation. I understand that you face the error where the game freezes and if you are on window mode you see at the top of the window "(Not responding)" and then the game crushes. Do I understand correctly?
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: ITEM WITH SPRITE
« Reply #4 on: April 13, 2013, 06:35:51 PM »

Hello, I worked out the issue with that one and managed to stop it from crashing! Quite chuffed, managed to get some serious item with scene interaction to work.

But now, i'm trying to completely remove the item/object from the game. Once the animation and the item are dropped - I go back to the previous scene and the item returns to the floor of the first scene! ARGH! any pointers? Would I need to declare a var in the previous scene init script? an if condition?

Thanks,
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

Jose

  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Posts: 134
    • View Profile
Re: ITEM WITH SPRITE
« Reply #5 on: April 13, 2013, 09:51:49 PM »

As far as I know there was a Game.DeleteItem() method to do what you want jimm84. You've a complete chapter in the WME help teaching how to use the inventory. Also the script reference section of the help becomes handy.
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: ITEM WITH SPRITE
« Reply #6 on: April 14, 2013, 09:48:03 AM »

For academic reasons, what was the issue jimm84?

As for your last question, you can use the Entity.Active attribute. When you use the code:

Code: WME Script
  1. var entity = Scene.GetNode("entityName");
  2. entity.Active = false;
  3.  

you make the entity invisible, therefore it is as if you removed it from the scene.
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: ITEM WITH SPRITE
« Reply #7 on: April 14, 2013, 10:10:03 AM »

Hello, it was really straight forward when I dug a little deeper.

on "Stone"
{
  actor.Talk("That should do it!");
  boulder.Play();
  Game.Interactive = true; (Game.Interactive = false;  ......... this was set to false, so when the animation played it killed interaction!)
  Game.DropItem("stone");
  Game.DeleteEntity("stone");
}

The var entity seems simple enough, although will this piece of script communicate with a previous scene? basic and event etc and item being used (in scene 2) triggers the item and object to vanish from scene1, if that makes sense?

And Hello Jose, I have started using the ref guide in help under help, very useful... actually essential. 

Cheers both.
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: ITEM WITH SPRITE
« Reply #8 on: April 21, 2013, 07:06:45 PM »

Hello, Sorry keeping running aground being a novice with this. I'm trying to this script to remove the item from the previous scene (call it scene1) and it through errors back. Is there a way like an absolute path or a global function that i need to communicate with in order to get object to vanish from scene one once animation in scene 2 has happened? (on stone)

#include "scripts\base.inc"

var stoneonfloor = Scene.GetNode("stone");
var boulder = this.GetSpriteObject();

on "FirstFrame"
{
 boulder.Pause();
}

on "LastFrame"
{
 boulder.Pause();
}
//----------------------


////////////////////////////////////////////////////////////////////////////////
on "LookAt"
{
  actor.GoToObject(this);
  actor.Talk("Blah");
}


////////////////////////////////////////////////////////////////////////////////
on "Take"
{
  actor.GoToObject(this);
  actor.Talk("...");
}


////////////////////////////////////////////////////////////////////////////////
on "Talk"
{
  actor.GoToObject(this);
  actor.Talk("Heavy");
}


////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // actor.GoToObject(this);
  //boulder.Play();
 
}
////////////////////////////////

on "Stone"
{
  actor.Talk("That should do it!");
  pebblesmash.Play();
  boulder.Play();
  Game.Interactive = true;
  Game.DropItem("stone");
  Game.DeleteEntity("stone");
  var stoneonfloor = Scene.GetNode("stone");
  stoneonfloor.Active = false;
  }

Kind regards,

Jimm
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/
 

Page created in 0.022 seconds with 20 queries.