Unhandled Events, more precise (SOLVED)

Started by PERXEO, Mon 03/04/2023 17:31:56

Previous topic - Next topic

PERXEO

In an unhandled event, I can know two parameters that are the what and the type to know if we are interacting with a hotspot, an object, an inventory object, etc...
I would also like to know how we can find out which is the exact object that has called that unhandled event, to know not only if it is an object or a character, but also what it is and what its specific ID is. That's possible?

Khris

#1
If you want individual responses, just handle the event instead. If this is about something else, please give some more information about what you're trying to achieve.

You can in theory handle all clicks in on_mouse_click yourself instead of simply calling Room.ProcessClick(), the idea is basically to use Game.GetLocationType to figure out the type, then use the according .GetAtScreenXY() function to find out the specific thing that was clicked. Now you can check .IsInteractionAvailable() and either call .RunInteraction() or a generic function. This way you know the specific thing without having to manually implement every event.

PERXEO

Thanks for the quick reply. What I want to achieve is that in the unhandledEvent event, there are random responses for the look, use, talk cases based on a random variable. But since many descriptions are feminine, masculine, singular and plural names, I have to adapt the answers to these concepts of gender and number. That's why I need to know exactly which object has triggered that unhanled event. For example, if I do "look at ceiling lamps", the answer cannot be the same as if I say "look at the wall". One is plural and the other is singular, so I want to make a little "parser" of responses, based on the exact object and a property that will indicate its gender and number.

Khris

You can set gender and number for each object etc. if you implement these as custom properties. Then you can use the method I described to read them and respond accordingly.

The alternative is a custom function where you pass both, like MyUnhandled(eGenderFemale, eCountOne); and to simply call that in the event function.

Afaik, most games use generic responses like "I don't see anything special" though, which will save you all this trouble.

PERXEO

Thanks for your answer.I've achieved my purpose!!

Code: ags
function unhandled_event(int what, int type) {
	String locname;
	String invname;
  int generoNumero;
  int theHotSpotID;
  int theObjectID;
  int theCharacterID;
	locname = Game.GetLocationName(mouse.x,mouse.y);
  String hotSpotProperty;
  if (what==1) //HOTSPOT
  {
    Hotspot *theHotSpot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
    //generoNumero=hotspot[what].GetProperty("generoNumero");
    //hotSpotProperty=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
    if (theHotSpot!=null)
    {
      theHotSpotID=theHotSpot.ID;
      generoNumero=hotspot[theHotSpotID].GetProperty("generoNumero");
   ;
    }else
    {
      Display("No hay un HOTSPOT");
      generoNumero=0;
      }
    
  }
  else if(what==2) //OBJECT
  {
      Object *theObject = Object.GetAtScreenXY(mouse.x, mouse.y);
      if (theObject!=null)
    {
      theObjectID=theObject.ID;
      generoNumero=object[theObjectID].GetProperty("generoNumero");
      Display("GENERO NUMERO %d ", generoNumero);
    }else
    {
   
      generoNumero=0;
      }
  }
  else if(what==3) //CHARACTER
  {
     Character *theCharacter = Character.GetAtScreenXY(mouse.x, mouse.y);
      if (theCharacter!=null)
    {
      theCharacterID=theCharacter.ID;
      generoNumero=object[theCharacterID].GetProperty("generoNumero");
      
    }else
    {
      Display("No hay un CHARACTER");
      generoNumero=0;
      }
  }

PERXEO

And then
Code: ags
function RandomLook(String name,  int generoNumero) {

  random = Random(5);
  String demostrativo;
  if (generoNumero==1)
  {
    demostrativo="ese";
   }else if (generoNumero==2)
   {
     demostrativo="esa";
   }
   else if (generoNumero==3)
   {
     demostrativo="esos";
   }
   else
   {
     demostrativo="esas";
    }
	if (random==0) cPerxeo.Say("Confía en mi, tu  no quieres mirar %s %s.",demostrativo,  name);
	else if (random==1) cPerxeo.Say("No hay nada importante en  %s %s.",demostrativo,  name);
	else if (random==2) cPerxeo.Say("Mirar %s %s es una perdida de tiempo.", demostrativo,  name);
	else if (random==3) cPerxeo.Say("No hay nada importante en %s %s.",demostrativo,  name);
	else if (random==4) cPerxeo.Say("No tiene mucho sentido mirar %s %s",demostrativo,  name);
	else if (random==5) cPerxeo.Say( "Vale, ya  miré %s %s, y ahora que?",demostrativo,  name);
}

SMF spam blocked by CleanTalk