Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: ShinjinNakamura on Tue 17/09/2013 16:34:17

Title: Object.GetAtScreenXY not working? [SOLVED]
Post by: ShinjinNakamura on Tue 17/09/2013 16:34:17
Salam,
I applied the following script to have my cursor change from walk icon to interact icon on mouse over. Thing is it works fine for characters, but when I apply to objects it just doesn't work.
Code (AGS) Select

function room_RepExec()
{
if (Object.GetAtScreenXY(mouse.x, mouse.y) == oPaper)
{
Mouse.Mode = eModeInteract;
}
else Mouse.Mode = eModeWalkto;

This was added under room script.
Title: Re: Object.GetAtScreenXY not working?
Post by: monkey0506 on Tue 17/09/2013 20:03:25
A few things to consider:

- You forgot to not rape the indentation that the editor provides.
- Did you add the room_RepExec method to the room script manually, or did you add it by clicking the "..." button in the room properties?
- You're probably going to be checking more than just one Object, so you may want to consider storing the result in an Object*. You should never call Object.GetAtScreenXY (or similar methods) multiple times in the same function unless you're checking different coordinates or there is reasonable probability that the result may have changed.
- You're using the Mouse structure statically. You should never do this. It functions for everything except mouse.x and mouse.y, but unless those properties are made static, all you're doing is creating inconsistencies in your code. You can still access the static members using the mouse instance.
- You're missing a closing brace. Even if this was just a sample snippet, it's still best practice to always include the right braces. You can still omit any non-relevant code in-between.
- Is the method being called? This ties into whether the function is properly linked through the editor, but you can test using a status label, a Display statement, or even AbortGame.
- You mentioned using something similar for characters. Without seeing that code also, it seems likely the two could be interfering with each other.
- On that note, it seems like you may even want this to apply to all Objects, not just oPaper. If that's the case, you could just test that the returned Object* is non-null.
- Also, are you implementing a BASS-style two-mode interface? If that's the case then cursor modes aren't really even necessary and you could just handle everything just-in-time in on_mouse_click. Separate cursor modes really only matter if you're using a multi-cursor interface like Sierra or LucasArts.
Title: Re: Object.GetAtScreenXY not working?
Post by: Khris on Tue 17/09/2013 20:10:47
Exactly, never implement global game mechanisms on a per-item or per-room basis. Never, ever.

An easy way of doing what you want is to add this inside repeatedly_execute in GlobalScript.asc:
Code (ags) Select
  if (mouse.Mode != eModeUseinv) {
    int lt = GetLocationType(mouse.x, mouse.y);
    int new_mode = eModeWalkto;
    if (lt == eLocationCharacter) new_mode = eModeTalkto;
    if (lt == eLocationObject || lt == eLocationHotspot) new_mode = eModeInteract;
    if (mouse.Mode != new_mode) mouse.Mode = new_mode;
  }
Title: Re: Object.GetAtScreenXY not working?
Post by: ShinjinNakamura on Sat 21/09/2013 06:03:40
All points taken into account, thanks  guys.
Title: Re: Object.GetAtScreenXY not working? [SOLVED]
Post by: EliasFrost on Sat 21/09/2013 10:22:11
Quote- You forgot to not rape the indentation that the editor provides.

..wat?
Title: Re: Object.GetAtScreenXY not working? [SOLVED]
Post by: Khris on Sat 21/09/2013 10:31:06
Don't feed the troll. :)
Title: Re: Object.GetAtScreenXY not working? [SOLVED]
Post by: monkey0506 on Sat 21/09/2013 19:31:13
Quote from: Dictionary.com (http://dictionary.reference.com/browse/rape)rape
verb (used with object)
7. to plunder (a place); despoil.
8. to seize, take, or carry off by force.

The act of destroying the indentation that the AGS script editor automatically provides is an act of violence and despoilment. Forcibly taking away a thing of such immense value is reprehensible. And I won't apologize for using a word in a valid context just because the connotation doesn't apply.
Title: Re: Object.GetAtScreenXY not working? [SOLVED]
Post by: Adeel on Sun 22/09/2013 12:00:40
Since the word 'rape' isn't applied to any living thing, let alone human beings. I'm unable to comprehend why the fuck would someone get offended by this.
Title: Re: Object.GetAtScreenXY not working? [SOLVED]
Post by: EliasFrost on Wed 23/10/2013 19:31:58
I wasn't offended, English is not my native language so I got a bit perplexed. No need to be hostile about it.