Problem with GetAtScreenXY (NULL)

Started by Akumayo, Sun 07/05/2006 22:52:08

Previous topic - Next topic

Akumayo

I have the following code in my On_Mouse_Click:

Code: ags

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
"Power is not a means - it is an end."

Ashen

#1
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.
I know what you're thinking ... Don't think that.

Akumayo

New Code:
Code: ags

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
"Power is not a means - it is an end."

Ashen

#3
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?
I know what you're thinking ... Don't think that.

Wretched

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.

Akumayo

Ahh, now maybe we are getting somewhere!  I have moved the code to before the pause script in on_mouse_click.  It now reads:
Code: ags

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...
"Power is not a means - it is an end."

Ashen

Try else if (IsGamePaused(). Sorry, forgot about that bit - otherwise I think it still blocks clicks.
I know what you're thinking ... Don't think that.

Akumayo

Alrighty then, new
Code: ags

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  :)
"Power is not a means - it is an end."

Ashen

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?
I know what you're thinking ... Don't think that.

Akumayo

#9
  • Handle Inventory Clicks in Script checked?
  • Nothing changing the mode?

    Well... I know I've done both of those.Ã,  Here's more info that might help:

    -The gui containing the inventory is a Popup-Modal
    -I tried this:
    Code: ags
    
    Ã,  if (button == eMouseLeft) {
    Ã,  Ã,  Display("Left-Clicking");
    Ã,  Ã,  if (mouse.Mode == eModeChoose) {
    Ã,  Ã,  Ã,  int current_item = 1;
    Ã,  Ã,  Ã,  while (current_item <= GetGameParameter(GP_NUMINVITEMS, 0, 0, 0) - 1) {
    Ã,  Ã,  Ã,  Ã,  if (InventoryItem.GetAtScreenXY(mouse.x, mouse.y) == inventory[current_item]) {
    Ã,  Ã,  Ã,  Ã,  Ã,  Display("Item Found"); player.ActiveInventory = inventory[current_item]; }
    Ã,  Ã,  Ã,  Ã,  current_item ++;
    Ã,  Ã,  Ã,  }
    Ã,  Ã,  }
    ...
    


    It too is located before the IsGamePaused check.Ã,  However, it shows no display messages when I left click over any of my popup-modal GUIs AND my Normal GUIs AND my Persistant GUIs.Ã,  Is it possible that the GUIs are blocking the clicks?Ã,  Is there a way around this?

    Once again, thank you for your patience.

    -Akumayo
"Power is not a means - it is an end."

Ashen

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?
I know what you're thinking ... Don't think that.

Akumayo

#11
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:
Code: ags

#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
"Power is not a means - it is an end."

Khris

Try this:
Code: ags
#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

Akumayo

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...
"Power is not a means - it is an end."

Khris

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().

Akumayo

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...
"Power is not a means - it is an end."

Ashen

I tried this:
Code: ags

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.)
I know what you're thinking ... Don't think that.

Dreadus

#17
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?

SMF spam blocked by CleanTalk