Basic Item Use Question

Started by dahui58, Mon 27/09/2010 00:21:42

Previous topic - Next topic

dahui58

I followed all the main tutorials and I couldn't find anything about how to use an item you have in your inventory. On the main tutorial it goes on about viewing an item in your inventory and I understand and can use that.

But now I would like to allow the player to use the item in the inventory with a hotspot to advance the plot.

There are a few functions I think look right (such as usewithInventory or interactwithitem) but I have no idea what code to put in for it to work.

The character has a wire, I would like him to use it with an broken machine which results in the wire going into the machine and working, however I want it to be allowed to be removed as well, as it is initally taken from a seperate outlet and I would like to be able to remove and place it in any of the outlets at any time to power up different areas. I am using basic variables to check whether or not the electricity is on in an area, but I'm having trouble putting the wire back into anything.

Thanks  ;D

Khris

Assuming the machine is a hotspot, the interaction event is "Use inventory on hotspot".
Inside the function, use if (player.ActiveInventory == iWire) or similar.

If the player is supposed to be able to remove it again, you need a wire object for every machine or outlet (or one per room).

dahui58

Quote from: Khris on Mon 27/09/2010 10:39:35
Assuming the machine is a hotspot, the interaction event is "Use inventory on hotspot".
Inside the function, use if (player.ActiveInventory == iWire) or similar.

If the player is supposed to be able to remove it again, you need a wire object for every machine or outlet (or one per room).

Yeah it's a hotspot.
Excellent thanks a lot

dahui58

Sorry but I don't know how to make an item the Active Inventory.
At the moment I have this in the Interact function for the Inventory Item...


function iWire_Interact()
{
player.ActiveInventory == iWire ;
}

But I get a "parse error" at player

Matti

You get a parse error because it should look like this:

Code: ags

function iWire_Interact()
{
  if (player.ActiveInventory == iWire){
    // post your code here
  }
}


The ActiveInventory is whichever item you've selected.

dahui58

Quote from: Mr. Matti on Mon 27/09/2010 12:54:42
You get a parse error because it should look like this:

Code: ags

function iWire_Interact()
{
  if (player.ActiveInventory == iWire){
    // post your code here
  }
}


The ActiveInventory is whichever item you've selected.

No thats to check if the active inventory is wire, and I've got no problem with that bit, i want to make the active inventory the wire, so when you interact with it in the inventory you can then use it on items in the environment.

dahui58

Quote from: Mr. Matti on Mon 27/09/2010 12:54:42


The ActiveInventory is whichever item you've selected.

How do I actually set that so when you click an inventory item it becomes the active inventory?

Matti

Man, I'm too tired, sorry.  ::)

Quote from: dahui58 on Mon 27/09/2010 12:36:11
function iWire_Interact()
{
player.ActiveInventory == iWire ;
}

But I get a "parse error" at player

You get the error because the "==" should be a single "="!

Khris

Quote from: dahui58 on Mon 27/09/2010 13:07:13
How do I actually set that so when you click an inventory item it becomes the active inventory?

This is the default behavior. In the default inventory GUI, click the arrow button, then the item.
If you're using another inventory GUI, you don't have to add code for every item. Just activate that inventory clicks are handled in script in the General settings pane, then add eButtonLeftinv behavior to on_mouse_click in Global.asc:

Code: ags
  else if (button == eMouseLeftinv) {
    InventoryItem*ii = inventory[game.inv_activated];  // get item that was clicked on
    if (mouse.Mode == eModeUseinv) ii.RunInteraction(eModeUseinv);  // use item on item
    else player.ActiveInventory = ii;   // set item active
  }

dahui58

Quote from: Khris on Mon 27/09/2010 17:00:24
Quote from: dahui58 on Mon 27/09/2010 13:07:13
How do I actually set that so when you click an inventory item it becomes the active inventory?

This is the default behavior. In the default inventory GUI, click the arrow button, then the item.
If you're using another inventory GUI, you don't have to add code for every item. Just activate that inventory clicks are handled in script in the General settings pane, then add eButtonLeftinv behavior to on_mouse_click in Global.asc:

Code: ags
  else if (button == eMouseLeftinv) {
    InventoryItem*ii = inventory[game.inv_activated];  // get item that was clicked on
    if (mouse.Mode == eModeUseinv) ii.RunInteraction(eModeUseinv);  // use item on item
    else player.ActiveInventory = ii;   // set item active
  }


Thanks I figured this out now, it turns out you had to click the far left side of the item in the inventory for it to work so I need to make more user friendly inventory icons.

Thanks everyone for helping

Khris

Check the ItemWidth and ItemHeight settings of your InventoryWindow. You're probably using graphics way bigger than the entered values.

dahui58

Quote from: Khris on Tue 28/09/2010 13:51:00
Check the ItemWidth and ItemHeight settings of your InventoryWindow. You're probably using graphics way bigger than the entered values.

the inventory has a height of 156 and a width of 220
I can't find any ItemWidth/Height variables, the size of my inventory item is about 55 wide 40 high

Matti

If you click the inventory the item width and height variables are right at the top of the panel to the right.

dahui58

Quote from: Mr. Matti on Tue 28/09/2010 17:35:51
If you click the inventory the item width and height variables are right at the top of the panel to the right.

For me the top is Background Color, BackgroundImage etc.. and all the stuff in the "Appearance" tab.

The only things I can find are Height, Left, Top, Width and zOrder in the layout panel

Matti

You have to select the actual inventory area (marked by white borders), not the whole GUI.

dahui58

Quote from: Mr. Matti on Tue 28/09/2010 19:03:07
You have to select the actual inventory area (marked by white borders), not the whole GUI.

I found it :D
Thanks a lot, this forum is so helpful and pretty quick to

SMF spam blocked by CleanTalk