Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KodiakBehr on Mon 20/05/2013 14:35:10

Title: Inventory Item Label
Post by: KodiakBehr on Mon 20/05/2013 14:35:10
Hi, this is going to sound really silly, but I've completely forgotten how to have an inventory item's name appear in a label on a mouseover!

Under repeatedly_execute_always, I inserted this line: 

InventoryItem*item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

And then later on in the same function I say,

lblInvDescription.Text=item.Name;

This causes crashes and sadness, and I'm clearly missing the big picture.  What is the correct way of doing this?

Thanks!
Title: Re: Inventory Item Label
Post by: Crimson Wizard on Mon 20/05/2013 14:37:04
Quote from: KodiakBehr on Mon 20/05/2013 14:35:10

InventoryItem*item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

And then later on in the same function I say,

lblInvDescription.Text=item.Name;

This causes crashes and sadness, and I'm clearly missing the big picture.  What is the correct way of doing this?

InventoryItem.GetAtScreenXY may return null, that's why you should test "item" pointer against one:
Code (ags) Select

if (item != null)
  lblInvDescription.Text=item.Name;
else
  lblInvDescription.Text="";
Title: Re: Inventory Item Label
Post by: KodiakBehr on Wed 22/05/2013 02:03:38
That did the trick.  Thanks a lot!