(SOLVED) InventoryItem.GetAtScreenXY returns NULL when it shouldn't

Started by Indrid Cold, Sun 17/01/2010 14:48:07

Previous topic - Next topic

Indrid Cold

Hello everyone,
I'm trying to create an interface which shows a GUI when you right click on any object (including inventory items) and then lets you decide what to do with it by clicking on a button. All this works just fine so far, except when right-clicking on an inventory item, in which case the GUI appears but buttons do nothing.

I've tried to debug and found that the problem is in this piece of code:
Code: ags
function doAction(int x, int y, int actionMode)
{
	InventoryItem* it=InventoryItem.GetAtScreenXY(x, y);
	if(it==null)
	{
		ProcessClick(x, y, actionMode);
	}
	else
	{
		it.RunInteraction(actionMode);
	}
}


Using the debugger (breakpoint on that "if"), I see that even if I right-click on an inventory item, the expression "if(it==null)" evaluates as true! The problem seems to be the same (or similar) as the one in this thread, which is 3 years old and remains unsolved...

I'm positive that InventoryItem.GetAtScreenXY gets the correct X and Y that I originally clicked on, before the pop-up GUI appeared, as I've checked this with appropriate "Display" calls here and there.

Also, in another instance when I call InventoryItem.GetAtScreenXY (to display the item's name in a textbox, called in "repeatedly_execute()") it seems to work fine.

I think once someone finds out what the problem is I'm going to feel really stupid, but as of this moment I can't figure it out... Any ideas?

EDIT: I forgot to add that the visibility of the GUI where the inventory appears on is "Normal, initially on". It's supposed to always be displayed, at the bottom of the screen.

EDIT 2: Um, never mind. It turns out that InventoryItem.GetAtScreenXY was running before the action GUI disappeared, so it checked on this location on it, instead of the inventory GUI. I solved it by making the action GUI disappear before the call to doAction.

SMF spam blocked by CleanTalk