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: AddAttachment and inventory item  (Read 6016 times)

0 Members and 1 Guest are viewing this topic.

valter.home

  • Supporter
  • Occasional poster
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 55
    • View Profile
AddAttachment and inventory item
« on: October 15, 2015, 03:11:42 PM »

I can't find a solution for two days, I try to ask you.
Is AddAttachment () usable with inventory items?

If I write:

Code: [Select]
var myItem = Game.GetItem("bat");
var myBool = myItem.AddAttachment ("entities\my_entity\my_entity.entity", false, 0, 0);
// I tried to change the parameters
Game.Msg (myBool);

myBool is true but there is no visible entity attached to the item.
If I use the instruction with molly entity becomes visible.
I need to attach an entity or sprite to object inventory when Game.SelectedItem = true.

At this time I connected entity with the cursor through game_loop.script but I don't like, the entity does not move smoothly.

Do you have any suggestions?
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: AddAttachment and inventory item
« Reply #1 on: October 15, 2015, 09:59:03 PM »

What exactly are you trying to do? You have added an item to your inventory with Game.GetItem("bat"). Where do you want the entity to be attached? To the item that you can see in the inventory? That is what I understand from your code.

But from what you say it seems you want to attach an entity on the cursor. If that is correct you need to attach it to the cursor object. Try:

Code: WME Script
  1. //I have not tested this code
  2. var cursor = Game.GetCursor();
  3. cursor.AddAttachment ("entities\my_entity\my_entity.entity", false, 0, 0);
  4.  
Logged

valter.home

  • Supporter
  • Occasional poster
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 55
    • View Profile
Re: AddAttachment and inventory item
« Reply #2 on: October 16, 2015, 12:22:16 PM »


You have added an item to your inventory with Game.GetItem("bat").


I'm confused, to add an item to the inventory I use Game.Take Item().
With Game.GetItem() I do this:
by the help: Existing items can be queried using the method Game.GetItem
I put the item object in a variable and then I attack it an entity ...
but in this way nothing happens

Quote
Code: WME Script
  1. //I have not tested this code
  2. var cursor = Game.GetCursor();
  3. cursor.AddAttachment ("entities\my_entity\my_entity.entity", false, 0, 0);
  4.  

I had already tried this code but it raises error Call to undefined method AddAttachment.
But if I change cursor with actor working properly.
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: AddAttachment and inventory item
« Reply #3 on: October 16, 2015, 09:55:05 PM »

Sorry, I meant Game.GetCursorObject(), which returns the cursor sprite. Game.GetCursor() returns the filename which is a string.
Logged

valter.home

  • Supporter
  • Occasional poster
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 55
    • View Profile
Re: AddAttachment and inventory item
« Reply #4 on: October 17, 2015, 08:23:56 AM »

Sorry, I meant Game.GetCursorObject(), which returns the cursor sprite. Game.GetCursor() returns the filename which is a string.

Very thanks anarchist for your help, but same mistake, Call to undefined method AddAttachment.
Perhaps it is impossible to attack an entity to mouse cursor with AddAttachment() ?
No one has ever had this need?
I searched the forum but I found only the solution to use game_loop...
It would be much better to use AddAttachment().
Logged

eborr

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 196
    • View Profile
Re: AddAttachment and inventory item
« Reply #5 on: October 17, 2015, 10:37:40 AM »

Have you thought about using the Item attribute CursorCombined. If I have understood your issue correctly this might work
Logged

valter.home

  • Supporter
  • Occasional poster
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 55
    • View Profile
Re: AddAttachment and inventory item
« Reply #6 on: October 17, 2015, 01:09:06 PM »

Have you thought about using the Item attribute CursorCombined. If I have understood your issue correctly this might work

Yes, I used this command, but what I'm doing is a bit more complicated.
It's difficult for me to explain in a few words because English is not my mother language but practically when I click on an inventory item I must simulate the sprite cursor in the exact position where it was when I selected item. When I move the cursor in SelectedItem the real cursor is hidden from CursorCombined = false and the entity attached simulates the mouse cursor.
I solved the problem of the coordinates and I do all this attacking entity with cursor image and I move it together item through game_loop.script but I think attacking the image directly to the item movement would be smoother.
I would just like to know if I'm wrong or if I can't use AddAttachment() with the cursor.
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: AddAttachment and inventory item
« Reply #7 on: October 17, 2015, 06:39:07 PM »

I think you want to do exactly what I wanted. What I do is when I click on an inventory item, I don't want the regular cursor to appear, but I want a custom cursor for each inventory item. In game.script I have:

Code: WME Script
  1. // clicking an inventory item
  2. else if(ActObj.Type == "item" && Item == null)
  3. {
  4.         ActObj.CursorCombined = false;
  5.         Game.SelectedItem = ActObj;
  6. }
  7.  

And in items.items file I have something like the following:

Code: [Select]
ITEM
{
   CURSOR_COMBINED = TRUE
   CAPTION = "Broken Door"
   NAME = "MeansOfEntry"
   IMAGE = "items\Broken Door.png"
   CURSOR = "items\Broken Door Chosen.png"
   CURSOR_HOVER = "items\Broken Door Chosen Highlighted.png"
   SCRIPT = "items\meansOfEntry.script"
}

No code in game_loop.script was needed for this.

Before selection


After selection


Or maybe I still don't understand what you want to do  :-[
Logged

valter.home

  • Supporter
  • Occasional poster
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 55
    • View Profile
Re: AddAttachment and inventory item
« Reply #8 on: October 18, 2015, 12:21:56 PM »

Or maybe I still don't understand what you want to do  :-[

ahem, no, but it's because of my bad English
when I click an itemt is lifted upward by about 40 pixels from the hotspot of the cursor
the mouse cursor is in a certain position and I memorize its coordinates
If you look at the two pictures you will see that the cursor is in two different positions because it depends on where the player has clicked on the item (position may still be different from the two images)





When the items have finished moving I call Game.SelectedItem() and the cursor disappears because of CursorCombined = false
I immediately put the entity with the sprite of the cursor at the coordinates that I had memorized (the cursor visible in the images is not the real cursor but is the entity)
So the player does not notice that the cursor has disappeared and when moving the item on the screen the real cursor is hidden in item but through game_loop.script the entity follows the item and the player has the impression of normally move its cursor
When there is Game.SelectedItem() = null I hide the entity and I put the cursor at the coordinates of the hidden entity
I do all this because using CursorCombined = true I can't define the coordinates to display the cursor, the cursor automatically goes to the hotspot of the item (and even it remains under to item not above).
I tried to change from code the item hotspot to put the visible cursor (CursorCombined = true) at my coordinates but I failed

One more thing, when I move a selected item on another I change the entity from arrow to gear but the entity remains under the item. Also to solve this problem  I read all the help without finding solutions



Thank you for all the time you give to me, I hope that soon I'll help too
Logged
 

Page created in 0.026 seconds with 20 queries.