context sensitive actions

Started by uoou, Sat 21/11/2009 22:56:11

Previous topic - Next topic

uoou

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.

uoou

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

uoou

Yes, you need to look at GetLocationType.

uoou


Crimson Wizard

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


GarageGothic

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.

uoou

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?

Crimson Wizard

#8
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
}

uoou

Thanks Wiz. Between you and Scavenger I'm all set :)

Gilbert

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

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

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

Crimson Wizard

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

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 ;)

SMF spam blocked by CleanTalk