Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: bx83 on Mon 25/03/2019 08:35:20

Title: Can you turn off an interaction (eg. talkto) with one command?
Post by: bx83 on Mon 25/03/2019 08:35:20
You can *check* if an interaction is available:
IsInteractionAvailable(eModeTalkto)

I was wondering if you can turn off interactions that are already?
You have an interaction for a character (cCharater_Talk() has been set and filled in with some code); how do you turn this off/on at will?
Or do you have to set a custom property and use this to turn it on or off through various mouse cursor trickery?
Title: Re: Can you turn off an interaction (eg. talkto) with one command?
Post by: Khris on Mon 25/03/2019 11:29:22
The short answer is to use a global variable, afaik AGS doesn't have a shortcut to turn off interactions.

There's also Game.DoOnceOnly(), although you'd have to manually call unhandled_event in the else block.
Title: Re: Can you turn off an interaction (eg. talkto) with one command?
Post by: Crimson Wizard on Mon 25/03/2019 11:52:43
I may suggest using Custom Properties to flag enabled/disabled interactions (you may now change their values at runtime too) because they are already bound to an object.

For a quick example:
Code (ags) Select

bool AllowRunInteraction(Character *c, CursorMode mode)
{
    if (mode == eModeTalkto && c.GetProperty("CanTalkTo") != 0) return true;
    if (mode == eModeLook && c.GetProperty("CanLookAt") != 0) return true;
    return false;
}

Code (ags) Select

function on_mouse_click(...)
{
....
   if (btn == eMouseLeft)
   {
       ....
       Character *ch = Character.GetAtScreenXY(mouse.x, mouse.y);
       if (AllowRunInteraction(ch, mouse.Mode))
          ch.RunInteraction(mouse.Mode);
   }
....
}
Title: Re: Can you turn off an interaction (eg. talkto) with one command?
Post by: bx83 on Mon 25/03/2019 18:07:05
As I thought - I've created a custom property.
Thanks :)