Jibble

Author Topic: Unhandled Events Not Working in a certain Room?  (Read 243 times)

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: Adventure Game Studio
  1. function BaggageTag_AnyClick()
  2. {
  3.   // WALK TO
  4.   if (Verbs.MovePlayer(160, 133)) {
  5.   player.FaceDirection(eDirectionRight);
  6.   }
  7.   // TALK TO
  8.   else if (Verbs.UsedAction(eGA_TalkTo)) {
  9.     Verbs.Unhandled();
  10.   }
  11.   // LOOK AT
  12.   else if(Verbs.UsedAction(eGA_LookAt)) {
  13.    player.Say("It's a passengers baggage tag. I can't read it without picking it up.");
  14.   }
  15.   // OPEN
  16.   else if(Verbs.UsedAction(eGA_Open)) {
  17.     Verbs.Unhandled();
  18.   }  
  19.   // CLOSE
  20.   else if(Verbs.UsedAction(eGA_Close)) {
  21.     Verbs.Unhandled();
  22.   }
  23.   // USE
  24.   else if(Verbs.UsedAction(eGA_Use)) {
  25.     Verbs.Unhandled();
  26.   }
  27.   // Push
  28.   else if(Verbs.UsedAction(eGA_Push)) {
  29.     Verbs.Unhandled();
  30.   }
  31.   // Pull
  32.   else if(Verbs.UsedAction(eGA_Pull)) {
  33.     Verbs.Unhandled();
  34.   }
  35.   // PICKUP
  36.   else if(Verbs.UsedAction(eGA_PickUp)) {
  37.     Verbs.Unhandled();
  38.   }
  39.   // GIVE TO (characters only)
  40.   else if(Verbs.UsedAction(eGA_GiveTo)) {
  41.     Verbs.Unhandled();
  42.   }  
  43.   //USE INV
  44.   else if(Verbs.UsedAction(eGA_UseInv)) {
  45.     Verbs.Unhandled();
  46.   }
  47.   else Verbs.Unhandled();
  48. }

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:

Re: Unhandled Events Not Working in a certain Room?
« Reply #1 on: 16 Jun 2021, 14:47 »
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.

Re: Unhandled Events Not Working in a certain Room?
« Reply #2 on: 16 Jun 2021, 15:01 »
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: Adventure Game Studio
  1. function BaggageTag_AnyClick()
  2. {
  3. // WALK TO
  4.   if (Verbs.UsedAction(eGA_WalkTo)) {
  5.    player.Walk(160, 135);
  6.   }
  7.   // TALK TO
  8.   else if (Verbs.UsedAction(eGA_TalkTo)) {
  9.     Verbs.Unhandled();
  10.   }
  11.   // LOOK AT
  12.   else if(Verbs.UsedAction(eGA_LookAt)) {
  13.     Verbs.Unhandled();
  14.   }
  15.   // OPEN
  16.   else if(Verbs.UsedAction(eGA_Open)) {
  17.     Verbs.Unhandled();
  18.   }  
  19.   // CLOSE
  20.   else if(Verbs.UsedAction(eGA_Close)) {
  21.     Verbs.Unhandled();
  22.   }
  23.   // USE
  24.   else if(Verbs.UsedAction(eGA_Use)) {
  25.     Verbs.Unhandled();
  26.   }
  27.   // Push
  28.   else if(Verbs.UsedAction(eGA_Push)) {
  29.     Verbs.Unhandled();
  30.   }
  31.   // Pull
  32.   else if(Verbs.UsedAction(eGA_Pull)) {
  33.     Verbs.Unhandled();
  34.   }
  35.   // PICKUP
  36.   else if(Verbs.UsedAction(eGA_PickUp)) {
  37.     Verbs.Unhandled();
  38.   }
  39.   // GIVE TO (characters only)
  40.   else if(Verbs.UsedAction(eGA_GiveTo)) {
  41.     Verbs.Unhandled();
  42.   }  
  43.   //USE INV
  44.   else if(Verbs.UsedAction(eGA_UseInv)) {
  45.     Verbs.Unhandled();
  46.   }
  47.   else Verbs.Unhandled();
  48. }

Matti

Re: Unhandled Events Not Working in a certain Room?
« Reply #3 on: 16 Jun 2021, 23:52 »
You have to make the walk command blocking, otherwise other things will happen simultaneously.

Code: Adventure Game Studio
  1. 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.
« Last Edit: 17 Jun 2021, 08:55 by Matti »

Re: Unhandled Events Not Working in a certain Room?
« Reply #4 on: 17 Jun 2021, 15:04 »
You have to make the walk command blocking, otherwise other things will happen simultaneously.

Code: Adventure Game Studio
  1. 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!

Re: Unhandled Events Not Working in a certain Room?
« Reply #5 on: 25 Jun 2021, 17:30 »
Before you waste any more time, here's the code fixed:

Code: Adventure Game Studio
  1. function BaggageTag_AnyClick()
  2. {
  3.   if (Verbs.MovePlayer(160, 135)) {
  4.     if (Verbs.UsedAction(eGA_LookAt)) {
  5.       player.Say("It's a baggage tag.");
  6.     }
  7.     else if (Verbs.UsedAction(eGA_TalkTo)) {
  8.       player.Say("I don't think I'll get a reply.");
  9.     }
  10.     else Verbs.Unhandled();
  11.   }
  12. }

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: Adventure Game Studio
  1. function Tree_AnyClick()
  2. {
  3.  
  4.   if (Verbs.UsedAction(eGA_LookAt)) {
  5.     player.FaceLocation(160, 125, eBlock);  // coordinates of tree base
  6.     player.Say("It's a large elm tree.");
  7.   }
  8.   else if (Verbs.UsedAction(eGA_TalkTo)) {
  9.     player.FaceDirection(eDirectionDown); // break 4th wall
  10.     player.Say("I don't think it's alive.");
  11.   }
  12.  
  13.   // all other verbs make the player approach first
  14.   else if (Verbs.MovePlayer(160, 135)) {
  15.     player.FaceDirection(eDirectionUp, eBlock); // face tree
  16.     // individual response for push/pull
  17.     if (Verbs.UsedAction(eGA_Push) || Verbs.UsedAction(eGA_Pull)) {
  18.       player.Say("I don't think I'm strong enough.");
  19.     }
  20.     else Verbs.Unhandled();
  21.   }
  22. }

« Last Edit: 25 Jun 2021, 17:31 by Khris »

Re: Unhandled Events Not Working in a certain Room?
« Reply #6 on: 28 Jun 2021, 10:56 »
Thank you Khris, that's really helpful for the project  :cool: