Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: TheMagician on Fri 07/11/2008 00:34:44

Title: Bug (?) with Game.GetLocationName
Post by: TheMagician on Fri 07/11/2008 00:34:44
I noticed a strange behaviour of "Game.GetLocationName()" but I don't know if it classifies as a bug.

Use Game.GetLocationName(player.x, player.y)  to get the name of a character or hotspot at the x- and y-coordinates of the player character.
Now test the game with F5 (which runs the game in a window) and the function works fine.
However, as soon as you move the mouse cursor (without clicking) out of the game window and then check again, the function returns an empty string ("").
As soon as you move the mouse back into the game window the function works again.

The rest of the game continues to work because the game-window doesn't actually lose focus. However this function only seems to work properly when the mouse pointer is within the game window.
Title: Re: Bug (?) with Game.GetLocationName
Post by: Pumaman on Fri 07/11/2008 02:21:56
This is an interesting spot. As far as I can tell it's nothing to do with moving the mouse out of the window, it happens when the mouse moves over a GUI (which on the default GUI will happen if you move it off the top, but not off the other sides).

Looking at the code, this is deliberate and probably dates back to when GetLocationName only worked with (mouse.x, mouse.y). But now, it does seem like a bug that it will always return blank while the mouse is over a GUI.

The problem is, it has always been like this, so I'd be a bit nervous to change it in case it broke peoples' games. I might fix it but add a backwards compatibility option to keep the old behaviour.
Title: Re: Bug (?) with Game.GetLocationName
Post by: monkey0506 on Fri 07/11/2008 09:38:25
If this behavior does change (including backwards-compatibility option ;)) I would like to ask if my request regarding unnamed locations returning a whitespace string be considered as well. My idea was that since the String type supports both null as well as empty strings ("") that Game.GetLocationName could return null if there is nothing (character/hotspot/object/inventory) at the specified co-ordinates, and an empty string could be used only at times when the actual Name property of the appropriate location is not set. This as opposed to the present behavior of nothing yielding an empty string "" and an unnamed location returning " ".
Title: Re: Bug (?) with Game.GetLocationName
Post by: Dualnames on Fri 07/11/2008 10:18:57
This might have something with pixel perfect click detection?
Title: Re: Bug (?) with Game.GetLocationName
Post by: TheMagician on Fri 07/11/2008 13:02:50
QuoteThe problem is, it has always been like this, so I'd be a bit nervous to change it in case it broke peoples' games.
^^The number of post where you have to say that has increased quite a bit recently ;)  Just shows how complex AGS has become.

It would be great if you could implement the "new" funcionality. My game really depends on it. And I thought the error only occurs in windowed mode. But if the GUIs cause the trouble it also affects fullscreen gameplay.
Title: Re: Bug (?) with Game.GetLocationName
Post by: Pumaman on Sun 09/11/2008 01:48:04
I've had a think about this, and decided that I will fix the issue that you describe, since it seems to be fairly obviously a bug based on AGS assuming that you'd only use GetLocationName with (mouse.x,mouse.y).

QuoteI would like to ask if my request regarding unnamed locations returning a whitespace string be considered as well. My idea was that since the String type supports both null as well as empty strings ("") that Game.GetLocationName could return null if there is nothing (character/hotspot/object/inventory) at the specified co-ordinates, and an empty string could be used only at times when the actual Name property of the appropriate location is not set. This as opposed to the present behavior of nothing yielding an empty string "" and an unnamed location returning " ".

I will fix the " " issue, so that an un-named object will return an empty string instead of a space.
However, changing GetLocationName to potentially return a null string would break everyone's game, and is unnecessary -- there is GetLocationType if you need to tell the difference.
Title: Re: Bug (?) with Game.GetLocationName
Post by: monkey0506 on Sun 09/11/2008 06:35:15
That's fair but previously you had stated that the whole reason for the whitespace string as opposed to the empty one was to be able to tell the difference. :D

Thanks Chris.
Title: Re: Bug (?) with Game.GetLocationName
Post by: Pumaman on Sun 09/11/2008 15:33:47
Yeah, originally it was, because originally there wasn't a GetLocationType function. But now there is :)