Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Akumayo on Sun 07/05/2006 22:52:08

Title: Problem with GetAtScreenXY (NULL)
Post by: Akumayo on Sun 07/05/2006 22:52:08
I have the following code in my On_Mouse_Click:


if (mouse.Mode == eModeChoose) {
Ã,  int current_item = 0;
Ã,  while (current_item <= GetGameParameter(GP_NUMINVITEMS, 0, 0, 0) - 1) {
Ã,  Ã,  if (InventoryItem.GetAtScreenXY(mouse.x, mouse.y) == inventory[current_item])
Ã,  Ã,  Ã,  player.ActiveInventory = inventory[current_item];
Ã,  Ã,  current_item ++;
Ã,  }
Ã,  Ã,  }


When I click on an inventory item, however, it doesn't become my active inventory, as it should.Ã,  (I have confirmed that the cursor is eModeChoose, before anyone asksÃ,  :P)

Does anyone see something I'm missing?

-Thanks in advance, Akumayo
Title: Re: Problem with GetAtScreenXY
Post by: Ashen on Sun 07/05/2006 23:33:07
The other obvious thing to check: have you enabled 'Handle inventory clicks in script? (And if so, is this under eMouseLeftInv rather than eMouseLeft.) (or eMouseRightInv, obviously...)

The other other thing is it seems a bit long winded - why not use if (InventoryItem.GetAtScreenXY(mouse.x, mouse.y) != null) player.ActiveInventory = InventoryItem.GetAtScreenXY(mouse.x, mouse.y); instead of the while loop?

EDIT: Actually, even that is a bit redundant - eMouseLeftInv clicks are only called ON items, so InventoryItem.GetAtScreenXY(mouse.x, mouse.y) will never be null.
Title: Re: Problem with GetAtScreenXY
Post by: Akumayo on Sun 07/05/2006 23:48:03
New Code:

else if (button == eMouseLeftInv) {
    if (mouse.Mode == eModeChoose) player.ActiveInventory = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  }


And... it still doesn't work.  I click the inventory item, and it doesn't get selected.

A bit of info that might be unimportant:
I have a check in On_key_press for the 'D' key, that displays the active inventory of the present player.  Whenever I click it while the inventory GUI is down, it says "Item: 0", but if I click it when the inventory GUI is up, it does nothing, like the key presses aren't being processed.  Could the clicks be not processing as well?

Any more help is appreciated.

-Regards, Akumayo
Title: Re: Problem with GetAtScreenXY
Post by: Ashen on Sun 07/05/2006 23:54:16
What 'type' of GUI is it? If it's popup modal, then key presses won't be processed unless the code is before the if (IsGamePaused() == 1) condition - and the same is true for on_mouse_click. Try moving the eMouseLeftInv and 'D' key condtions.

If that doesn't work (or it's not a modal GUI) - can you get ANYTHING (like a Display command) to run when you click an inventory item, or is it just setting it as active that's a problem?
Title: Re: Problem with GetAtScreenXY
Post by: Wretched on Mon 08/05/2006 01:00:35
Might not be your problem but you should change
int current_item = 0;
to
int current_item = 1;

as the first inventory item is number 1.
Title: Re: Problem with GetAtScreenXY
Post by: Akumayo on Mon 08/05/2006 01:10:00
Ahh, now maybe we are getting somewhere!  I have moved the code to before the pause script in on_mouse_click.  It now reads:

function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  {
   
  if (button == eMouseLeftInv) {
    Display("Clicked Inventory item.");
    if (mouse.Mode == eModeChoose) { Display("Found Inventory"); player.ActiveInventory = InventoryItem.GetAtScreenXY(mouse.x, mouse.y); }
  }
   
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
    {
    }
...
...


When I click on the inventory item, nothing at all happens.  Any ideas?  I'm at a loss...
Title: Re: Problem with GetAtScreenXY
Post by: Ashen on Mon 08/05/2006 01:15:36
Try else if (IsGamePaused(). Sorry, forgot about that bit - otherwise I think it still blocks clicks.
Title: Re: Problem with GetAtScreenXY
Post by: Akumayo on Mon 08/05/2006 01:18:21
Alrighty then, new

function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã,  {
Ã,  Ã, 
Ã,  if (button == eMouseLeftInv) {
Ã,  Ã,  Display("Clicked Inventory item.");
Ã,  Ã,  if (mouse.Mode == eModeChoose) { Display("Found Inventory"); player.ActiveInventory = InventoryItem.GetAtScreenXY(mouse.x, mouse.y); }
Ã,  }
Ã,  Ã, 
Ã,  else if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
Ã,  Ã,  {
Ã,  Ã,  }

Ã,  else if (button == eMouseLeft)
Ã,  Ã,  {
...


And still, there are no displays at all when I click on the item.Ã,  There is nothing...

Thank you for your patience with this  :)
Title: Re: Problem with GetAtScreenXY
Post by: Ashen on Mon 08/05/2006 01:28:15
OK this is just weird. I made an eModeChoose, copied exactly that code - and it works fine.

Are you absolutely sure there isn't something that's changing the mode (although that should still display the first line), and that 'Handle inventory clicks in script' is checked?
Title: Re: Problem with GetAtScreenXY
Post by: Akumayo on Mon 08/05/2006 01:44:50
Title: Re: Problem with GetAtScreenXY
Post by: Ashen on Mon 08/05/2006 12:03:07
IIRR, on_mouse_click is never run when you click on a GUI (unless it's an inventory item and 'Handle clicks...' is checked - and that doesn't seem to be working for you) so for that code Yes, the GUI is 'blocking' the click.

Ways round it: You could use the eEventGUIMouseUp/Down conditions in on_event, or you could add an interaction to every item to make it active when eModeChoose is used (or use unhandled_event to cover them all).

How big would your game be, zipped? Is it possible you could upload it somewhere so I can try to figure out why eMouseLeftInv isn't working?
Title: Re: Problem with GetAtScreenXY
Post by: Akumayo on Wed 10/05/2006 23:53:21
I think I'll try using the unhandled_event condition, and get back to you on how that works out.Ã,  Thanks for your help so far again.

EDIT:

Tried out the unhandled_event condition like so:

#sectionstart unhandled_event  // DO NOT EDIT OR REMOVE THIS LINE
function unhandled_event(int what, int type) {
  if (what == 5 && type == 4) {
    Display("Unhandled Event is running.");
    player.ActiveInventory = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  }
}
#sectionend unhandled_event  // DO NOT EDIT OR REMOVE THIS LINE


And still, you guessed it, the message does not display, and the inventory is not selected...Ã,  I'm going to cry now...Ã,  :'(

Joking of course, but I am getting a mite frustrated...Ã,  Any other ideas maybe?Ã,  Once again again, thanks for your help so far.

-Regards, Akumayo
Title: Re: Problem with GetAtScreenXY
Post by: Khris on Thu 11/05/2006 01:45:41
Try this:
#sectionstart unhandled_eventÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function unhandled_event(int what, int type) {
Ã,  Display("what: %d, type: %d", what, type);
}
#sectionend unhandled_eventÃ,  // DO NOT EDIT OR REMOVE THIS LINE
Title: Re: Problem with GetAtScreenXY
Post by: Akumayo on Thu 11/05/2006 01:51:17
I tried that code just now, and the message wasn't returned no matter where I clicked (including the inventory item).  Perhaps my AGS editor has a problem?  I'll try downloading AGS over, and importing the game into it, and see if anything happens...
Title: Re: Problem with GetAtScreenXY
Post by: Khris on Thu 11/05/2006 01:55:30
AFAIK, unhandled_event() is only called after ProcessClick() triggered an interaction without child actions.
If you don't call unhandled_event() yourself, make sure that AGS hits a call to ProcessClick() somewhere in on_mouse_click().
Title: Re: Problem with GetAtScreenXY
Post by: Akumayo on Thu 11/05/2006 02:27:52
I downloaded a new copy of AGS, and the problem persists.

More bad news also, I tried placing an interaction in the inventory item's "Other Click on Item" script, and it doens't run when clicked either.  I suppose I can use a Listbox instead of the inventory for what I need...  thanks for trying anyway everybody...
Title: Re: Problem with GetAtScreenXY (NULL)
Post by: Ashen on Thu 11/05/2006 11:35:31
I tried this:

function unhandled_event(int what, int data) {
  if (what == 5) {
    if (mouse.Mode == eModeChoose) {
      Display("Found Inventory");
      player.ActiveInventory = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
    }
  }   
}


And it worked fine - but if unhandled_event isn't running for you at all that's a problem. Does it work if you start a new game? If so, there's probably something in another part of your script causing the problem - how do you feel about uploading it to be checked? (A fresh set of eyes - or several fresh sets - can usually spot these things quicker than whoever actually wrote it.)
Title: Re: Problem with GetAtScreenXY (NULL)
Post by: Dreadus on Sat 02/09/2006 17:14:16
I got this same problem, sucks bad...
Could anyone shed some new light?

edit: and Akumayo, Did you find that your inventory items "clickable hotspot" was offset and weird?