Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: PightyMirate on Wed 16/06/2021 14:43:06

Title: Unhandled Events Not Working in a certain Room?
Post by: PightyMirate on Wed 16/06/2021 14:43:06
OK I am sorry for another post  :cheesy:

I have an OBJECT in my first room which can be picked up and added to the inventory.

I have been trying to figure out all day how to make the character move to the object before interacting with it (which is now done) but none of the unhandled event verbs are working.

Code (ags) Select
function BaggageTag_AnyClick()
{
  // WALK TO
  if (Verbs.MovePlayer(160, 133)) {
  player.FaceDirection(eDirectionRight);
  }
  // TALK TO
  else if (Verbs.UsedAction(eGA_TalkTo)) {
    Verbs.Unhandled();
  }
  // LOOK AT
  else if(Verbs.UsedAction(eGA_LookAt)) {
   player.Say("It's a passengers baggage tag. I can't read it without picking it up.");
  }
  // OPEN
  else if(Verbs.UsedAction(eGA_Open)) {
    Verbs.Unhandled();
  } 
  // CLOSE
  else if(Verbs.UsedAction(eGA_Close)) {
    Verbs.Unhandled();
  }
  // USE
  else if(Verbs.UsedAction(eGA_Use)) {
    Verbs.Unhandled();
  }
  // Push
  else if(Verbs.UsedAction(eGA_Push)) {
    Verbs.Unhandled();
  }
  // Pull
  else if(Verbs.UsedAction(eGA_Pull)) {
    Verbs.Unhandled();
  }
  // PICKUP
  else if(Verbs.UsedAction(eGA_PickUp)) {
    Verbs.Unhandled();
  }
  // GIVE TO (characters only)
  else if(Verbs.UsedAction(eGA_GiveTo)) {
    Verbs.Unhandled();
  } 
  //USE INV
  else if(Verbs.UsedAction(eGA_UseInv)) {
    Verbs.Unhandled();
  }
  else Verbs.Unhandled();
}


The unhandled events are working perfectly for other hotspots and for the iBlueCup in the demo room 1, and I have copied the exact code over to my custom room but I cannot use any of the unhandled events, only the player walks to the object and faces the right direction.

I have tried putting this in Global Script also but still nothing  :embarrassed:
Title: Re: Unhandled Events Not Working in a certain Room?
Post by: PightyMirate on Wed 16/06/2021 14:47:05
I have also tried adding the prompts into the events page (AnyClick, InteractObject etc) but still nothing is happening.

I have also just tried the code for another object in the room and having the same issues.
Title: Re: Unhandled Events Not Working in a certain Room?
Post by: PightyMirate on Wed 16/06/2021 15:01:40
OK so I have fixed the Unhandled Events, they are now working. it seems they have to be displayed in a certain order.

However I cannot for life or money figure out how to make the player walk to a certain position before ANY interaction with the object. I have tried the below code and the player will walk to the coordinates when clicking 'Walk To', but for example if I say 'Look at Baggage Tag' the player will remain where he is on the screen and say ''Its a baggage tag'' before walking to the object.

I have seen many many posts about this on the forums, but they all seem so complicated? Why can we not move to objects before interactions the same as hotspots?  :sad:

Please help

BAD CODE:

Code (ags) Select
function BaggageTag_AnyClick()
{
// WALK TO
  if (Verbs.UsedAction(eGA_WalkTo)) {
   player.Walk(160, 135);
  }
  // TALK TO
  else if (Verbs.UsedAction(eGA_TalkTo)) {
    Verbs.Unhandled();
  }
  // LOOK AT
  else if(Verbs.UsedAction(eGA_LookAt)) {
    Verbs.Unhandled();
  }
  // OPEN
  else if(Verbs.UsedAction(eGA_Open)) {
    Verbs.Unhandled();
  } 
  // CLOSE
  else if(Verbs.UsedAction(eGA_Close)) {
    Verbs.Unhandled();
  }
  // USE
  else if(Verbs.UsedAction(eGA_Use)) {
    Verbs.Unhandled();
  }
  // Push
  else if(Verbs.UsedAction(eGA_Push)) {
    Verbs.Unhandled();
  }
  // Pull
  else if(Verbs.UsedAction(eGA_Pull)) {
    Verbs.Unhandled();
  }
  // PICKUP
  else if(Verbs.UsedAction(eGA_PickUp)) {
    Verbs.Unhandled();
  }
  // GIVE TO (characters only)
  else if(Verbs.UsedAction(eGA_GiveTo)) {
    Verbs.Unhandled();
  } 
  //USE INV
  else if(Verbs.UsedAction(eGA_UseInv)) {
    Verbs.Unhandled();
  }
  else Verbs.Unhandled();
}
Title: Re: Unhandled Events Not Working in a certain Room?
Post by: Matti on Wed 16/06/2021 23:52:49
You have to make the walk command blocking, otherwise other things will happen simultaneously.

Code (ags) Select
player.Walk(160, 135, eBlock);

If this doesn't help than the problem is related to the Tumbleweed template and I can't help you with that as I've never used it. But I don't understand why there would be a difference between walking to hotspots and walking to objects.
Title: Re: Unhandled Events Not Working in a certain Room?
Post by: PightyMirate on Thu 17/06/2021 15:04:22
Quote from: Matti on Wed 16/06/2021 23:52:49
You have to make the walk command blocking, otherwise other things will happen simultaneously.

Code (ags) Select
player.Walk(160, 135, eBlock);

If this doesn't help than the problem is related to the Tumbleweed template and I can't help you with that as I've never used it. But I don't understand why there would be a difference between walking to hotspots and walking to objects.

Thanks Matti, that's all working correctly now!
Title: Re: Unhandled Events Not Working in a certain Room?
Post by: Khris on Fri 25/06/2021 17:30:01
Before you waste any more time, here's the code fixed:

Code (ags) Select
function BaggageTag_AnyClick()
{
  if (Verbs.MovePlayer(160, 135)) {
    if (Verbs.UsedAction(eGA_LookAt)) {
      player.Say("It's a baggage tag.");
    }
    else if (Verbs.UsedAction(eGA_TalkTo)) {
      player.Say("I don't think I'll get a reply.");
    }
    else Verbs.Unhandled();
  }
}


This is all you need.

1. wrapping your actions in a Verbs.MovePlayer(x, y) if block makes sure that the player always approaches the hotspot/object/character first, and it also replicates the LucasArts behavior where you can click somewhere else to cancel the action (a blocking walk doesn't allow that).

2. Only handle Verbs that cause individual responses, then simply use  else Verbs.Unhandled()  (this is basic programming logic and not specific to AGS or the Tumbleweed template)

Note that you can diverge from this structure if you don't want the character to always approach the hotspot first. Looking at / talking to a tree doesn't require standing directly next to it for instance:

Code (ags) Select
function Tree_AnyClick()
{

  if (Verbs.UsedAction(eGA_LookAt)) {
    player.FaceLocation(160, 125, eBlock);  // coordinates of tree base
    player.Say("It's a large elm tree.");
  }
  else if (Verbs.UsedAction(eGA_TalkTo)) {
    player.FaceDirection(eDirectionDown); // break 4th wall
    player.Say("I don't think it's alive.");
  }

  // all other verbs make the player approach first
  else if (Verbs.MovePlayer(160, 135)) {
    player.FaceDirection(eDirectionUp, eBlock); // face tree
    // individual response for push/pull
    if (Verbs.UsedAction(eGA_Push) || Verbs.UsedAction(eGA_Pull)) {
      player.Say("I don't think I'm strong enough.");
    }
    else Verbs.Unhandled();
  }
}


Title: Re: Unhandled Events Not Working in a certain Room?
Post by: PightyMirate on Mon 28/06/2021 10:56:04
Thank you Khris, that's really helpful for the project  :cool: