Problem with my unhandled function re objects

Started by FortressCaulfield, Sat 25/05/2024 15:24:55

Previous topic - Next topic

FortressCaulfield

My expectation is that the 2nd line with the "achieved sentience" result should fire if the player tries to talk to an object that doesn't have its own talk function. It works fine for hotspots but for objects it returns the generic "the heck?" line. Why?

Code: ags
// *******************
// unhandled misclicks
// *******************
// WHAT- 1- hotspot, 2-object, 3-char, 4-nothing, 5- inv
// TYPE  1- look, 2- int, 3- use, 4- talk, 7- PU, 8- CM8, 9- CM9
function unhandled_event (int what, int type)
{
  if (what == 4) return; //no message for non-existent clicks
  if ((type == 4) && (what != 3)) // try to talk to non person. objects repping persons need their own line in room
  {
    cOva.Say("Hey there! Achieved sentience?");
    Wait(16);
    cOva.Say("No? Good.");
    cOva.Say("After the Cyberfork uprising last year, you can't be too careful!");
    return;
  }
  if (type == 3) // invalid item usage
  {
    if (what == 3) // giving things to chars
    {
      cOva.Say("No, I'd better keep that.");
      return;
    }
    switch(cOva.ActiveInventory)
    {
      case iAnalopticon: cOva.Say("That doesn't need analyzing."); return;
      case iHypercaulk: cOva.Say("That doesn't need to be any stickier."); return;
      case iStapler: cOva.Say("That doesn't need stapling."); return;
      default: cOva.Say("Those two things will not produce a successful merger."); return;   
    }
  }
  cOva.Say("The heck?");
}
"I can hear you! My ears do more than excrete toxic mucus, you know!"

Khris


FortressCaulfield

So it converts the talk into an interact? That's annoying. Wish we had more access to core functions so we could tweak things like that.

Oh well at least now I know, thanks!
"I can hear you! My ears do more than excrete toxic mucus, you know!"

Crimson Wizard

#3
Quote from: FortressCaulfield on Sun 26/05/2024 20:36:01So it converts the talk into an interact? That's annoying. Wish we had more access to core functions so we could tweak things like that.

You do have an option to fine tune the interaction behavior if you don't rely on "unhandled_event" but script your own interaction logic. Normally this is done with the help of GetLocationType and IsInteractionAvailable functions in on_mouse_click:
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_General.html#getlocationtype
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_General.html#isinteractionavailable

function like Object.GetAtScreenXY, and similar, can be useful in this too.

For a quick example:
Code: ags
function on_mouse_click(MouseButton button)
{
     if (button == eButtonLeft)
     {
          if (IsInteractionAvailable(mouse.x, mouse.y, mouse.Mode))
          {
              Room.ProcessClick(mouse.x, mouse.y, mouse.Mode);
          }
          else
          {
              // do your custom "unhandled interaction" handling
          }
     }
}

Khris

You can write your own global click handler (edit on_mouse_click) and you own unhandled code, then base it on for instance GetLocationType() and mouse.Mode, if you want.

SMF spam blocked by CleanTalk