There is a new version of the forums ready for testing. Please post here if you're willing to help test! We could also use the help of coders!

Author Topic: Lose the Key after using the Doors syntax in Thumbleweed  (Read 219 times)

AndreasBlack

  • Max Fury that's me
Can't see anything about it in the manual, but i've been known to be blind before so. Maybe it's there, just not written as an actual example.

How do i lose the key from the inventory forever after it's been unlocked? I've managed to do it with a weird solution, but there's gotta be a proper way to do it inside a normal function and not repetedly execute like i'm using.

Weird solution so far, a simply check with some synthax like "doors.getdoorstate==0")  ???

Code: Adventure Game Studio
  1. function hBedroom_Door_AnyClick()
  2. {
  3.  
  4.  
  5. if (Doors.AnyClickSpecial(10, oBedroom_Door.ID,  41,  116, eDirectionLeft, 1, 200, 145, eDirectionLeft, aDoor_Opened, aDoor_Closed, 10, 0) == 0)
  6. Verbs.Unhandled() || cRain.ActiveInventory==iBedroom_Key;
  7.  
  8.  
  9.  
  10. function hBedroom_Door_UseInv()
  11. {
  12.  
  13.  
  14. if (cRain.ActiveInventory==iBedroom_Key)
  15.  
  16. {
  17.   Doors.SetDoorState(10, 2);
  18.  
  19.   Key_Unlocked=1;
  20.  
  21.   if (Key_Unlocked==1 && !cRain.Walk(41, 121, eBlock))
  22.  
  23. {
  24.       aDoor_Unlocked.Play();
  25.  
  26. }
  27. }
  28.  
  29. }
  30.  
  31. //and finally........
  32.  
  33. function room_RepExec()
  34. {
  35. if (Key_Unlocked==1)
  36.  
  37. {
  38.  
  39.   if (cRain.HasInventory(iBedroom_Key))
  40.   {
  41.   cRain.LoseInventory(iBedroom_Key);
  42.   }  
  43.  
  44. }
  45.  
  46.  
  47. }




Re: Lose the Key after using the Doors syntax in Thumbleweed
« Reply #1 on: 17 May 2022, 11:50 »
With the Tumbleweed template, you're supposed to use the AnyClick event for all hotspot interactions.

Try this:
Code: Adventure Game Studio
  1. function hBedroom_Door_AnyClick() {
  2.   // standard behavior
  3.   if (Doors.AnyClickSpecial(10, oBedroom_Door.ID,  41,  116, eDirectionLeft, 1, 200, 145, eDirectionLeft, aDoor_Opened, aDoor_Closed, iBedroom_Key.ID, 0) == 0) Verbs.Unhandled();
  4.   // if key was used, lose it
  5.   if (Verbs.UsedAction(eGA_UseInv) && player.ActiveInventory == iBedroom_Key) player.LoseInventory(iBedroom_Key);
  6. }

If the door is initially locked, using the key on it will unlock it, so we can safely assume that happened.

abstauber

  • Cavefish
  • Mittens Knight
  • still mowing the lawn
    • Best Innovation Award Winner 2021, for contributions to the ready-to-use UI designs and elements that mimic the most iconic designs we all know and love, most notably Tumbleweed Verbs and 9-verb MI Style UI, as well as additional UI helper modules such as CustomDialogGUI and ButtonHelper.
    • abstauber worked on one or more games that won an AGS Award!
    •  
    • abstauber worked on one or more games that was nominated for an AGS Award!
Re: Lose the Key after using the Doors syntax in Thumbleweed
« Reply #2 on: 17 May 2022, 12:06 »
To be 100% safe, you can also check, if the door has actually been unlocked.
Doors.GetDoorState(door_id) == 0
Code: Adventure Game Studio
  1. function hBedroom_Door_AnyClick() {
  2.   // standard behavior
  3.   if (Doors.AnyClickSpecial(10, oBedroom_Door.ID,  41,  116, eDirectionLeft, 1, 200, 145, eDirectionLeft, aDoor_Opened, aDoor_Closed, iBedroom_Key.ID, 0) == 0) Verbs.Unhandled();
  4.   // if key was used, lose it
  5.   if (Verbs.UsedAction(eGA_UseInv) && player.ActiveInventory == iBedroom_Key && Doors.GetDoorState( oBedroom_Door.ID) == 0 ) player.LoseInventory(iBedroom_Key);
  6. }
  7.  

AndreasBlack

  • Max Fury that's me
Re: Lose the Key after using the Doors syntax in Thumbleweed
« Reply #3 on: 17 May 2022, 12:18 »
intermittent fasting isn't to recommend either when doing this, i suppose........ :-X

edit: HAHA!!!!  (laugh) What a smart ***, added the KEYS in the ROOM LOAD. ROFL, fantastic logic!!! What did i expect? Nothing wrong with the code, like always!  (laugh) (roll)


« Last Edit: 17 May 2022, 18:57 by AndreasBlack »