Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: uoou on Sat 21/11/2009 22:56:11

Title: context sensitive actions
Post by: uoou on Sat 21/11/2009 22:56:11
There might be a proper name for this which, if I knew it, would help me search. But I don't know it. So...

I want to have it so that clicking on a thing performs the default action (and for this default action to be reflected in cursor changes when you mouse over something). For example, when I click on the ground, I walk there and when I click on a character I talk to them. Without having to rotate the actions myself.

So I thought I'd write a function called in repeatedly execute which checks whether the mouse is over an object/character/hotspot and changes the mouse mode accordingly. Is this possible? And if so, is it practical or will it hit performance too much?

I can't find anything in the manual to check whether the mouse is over a character/object etc. (that is, any character, not a particular character). Is there a way to do this?

Thank you.
Title: Re: context sensitive actions
Post by: uoou on Sat 21/11/2009 23:03:19
(btw, I realise (I think) I could put code on every character/object to change the mouse mode when they're moused over but I'd rather do it generalised if possible)
Title: Re: context sensitive actions
Post by: uoou on Sat 21/11/2009 23:08:23
Yes, you need to look at GetLocationType.
Title: Re: context sensitive actions
Post by: uoou on Sat 21/11/2009 23:09:01
Wicked thanks.
Title: Re: context sensitive actions
Post by: Crimson Wizard on Sat 21/11/2009 23:16:54
Sometimes it may have sense to post a questin on forum. If no one answers you still are stimulated to find an answer yourself.
;D
Title: Re: context sensitive actions
Post by: uoou on Sat 21/11/2009 23:20:13
 ;D
Title: Re: context sensitive actions
Post by: GarageGothic on Sun 22/11/2009 02:45:28
You could also use custom properties (look it up in the manual) to set the default actions. This ensures a bit more flexibility, e.g. in case you for technical reasons end up using a character in place of an object and don't want it to have "talk" as the default action.
Title: Re: context sensitive actions
Post by: uoou on Sun 22/11/2009 15:58:29
Thank's GarageGothic, I'll keep that in mind.

Is there a way, after using GetLocationType to discover that there's a (say) object under the mouse, to discover which particular object that is and thus get access to its properties?
Title: Re: context sensitive actions
Post by: Crimson Wizard on Sun 22/11/2009 16:07:49
Quote from: uoou on Sun 22/11/2009 15:58:29
Is there a way, after using GetLocationType to discover that there's a (say) object under the mouse, to discover which particular object that is and thus get access to its properties?

Character.GetAtScreenXY(int x, int y)
Hotspot.GetAtScreenXY(int x, int y)
Object.GetAtScreenXY(int x, int y)

can be used like this:

Character * char = Character.GetAtScreenXY(mouse.x, mouse.y);

if (char)
{
  // there's a character under the mouse
}
Title: Re: context sensitive actions
Post by: uoou on Sun 22/11/2009 16:35:17
Thanks Wiz. Between you and Scavenger I'm all set :)
Title: Re: context sensitive actions
Post by: Gilbert on Mon 23/11/2009 01:05:18
I doubt whether that works.

1. Be careful that 'char' is a reserved word, so try not to use this as a variable name. (I understand that the code example is just for demonstration, but it may not work if copied directly.)
2. The Character* type is a pointer, you should not just check whether it's non-zero with 'if (char)'.

So:

Character * tmpchar = Character.GetAtScreenXY(mouse.x, mouse.y);

if (tmpchar!=null)
{
   // there's a character under the mouse
}
Title: Re: context sensitive actions
Post by: Crimson Wizard on Mon 23/11/2009 13:23:34
Quote from: Gilbet V7000a on Mon 23/11/2009 01:05:18
1. Be careful that 'char' is a reserved word, so try not to use this as a variable name. (I understand that the code example is just for demonstration, but it may not work if copied directly.)
Damn right, my mistake.

Quote from: Gilbet V7000a on Mon 23/11/2009 01:05:18
2. The Character* type is a pointer, you should not just check whether it's non-zero with 'if (char)'.

So:

Character * tmpchar = Character.GetAtScreenXY(mouse.x, mouse.y);

if (tmpchar!=null)
{
  // there's a character under the mouse
}


Actually it is not necessary; I guess AGS makes a pointer be checked as integer in such case, as most C/C++ compilers do, and treats result as boolean expression.
At least I used this kind of condition many times in my projects, including one game which I completed, and that works ;)