How to interact with "popover" object after LockView and before UnlockView

Started by snobes, Wed 11/09/2024 02:56:53

Previous topic - Next topic

snobes

Hello, everyone starts their post this way, but I cannot find a solution to my problem in the manual and the forums (I've searched both).

TLDR: how do I interact with "popover" objects after the cEgo.LockView is called and before the cEgo.UnlockView is called?

I have a sprite, which is the inside of a wastebasket. Additionally, there is a wastebasket hotspot in the room. Here is the game logic:

- player interacts with the wastebasket hotspot
- the interact with event is fired
- the character walks to the wastebasket
- the character bends down
- while the character is still bent, the inside of the wastebasket object becomes visible and remains until the player interacts with the inside of the wastebasket object
- the interact with event is fired for the inside of the wastebasket object
- the character stands up
- the player resumes normal control of the character

My issue is after calling cEgo.LockView(), the cursor becomes "disabled" along with the nav bar. While cEgo is locked, how to allow the cursor to be usable.

The following is my attempt at the problem:

Code: ags
bool wastebasketClicked = false;

function wastebasket_Interact(Hotspot *theHotspot, CursorMode mode)
{
  int destX = 57;
  int destY = 148;
  
  cEgo.Walk(destX, destY, eBlock);
  cEgo.LockView(CLARA_MAIN_CABIN);
  cEgo.x = 49;
  cEgo.y = 147;
  
  cEgo.Animate(0, 5, eOnce, eBlock);

  oInsideWasteBasket.Visible = true;
  wastebasketClicked = false;
  
  // this is my attempt, but the cursor remains disabled from the LockView function call
  mouse.EnableMode(eModeInteract);
  mouse.Mode = eModeInteract;
  
  while (!wastebasketClicked) {
      Wait(1);
  }
  
  oInsideWasteBasket.Visible = false;
    
  cEgo.Animate(1, 5, eOnce, eBlock);
  cEgo.x = destX;
  cEgo.y = destY;
  cEgo.UnlockView();
}

function oInsideWasteBasket_Interact(Object *theObject, CursorMode mode)
{
    wastebasketClicked = true;  // Set the flag to allow the script to proceed
    Display("You see something inside the wastebasket.");
    
    // Optionally, hide the object again after the click
    oInsideWasteBasket.Visible = false;
}

Crimson Wizard

This problem is not related to LockView. LockView simply keeps a particular character locked at a certain view, nothing else.

This is the code that locks your game controls:
Code: ags
  while (!wastebasketClicked) {
      Wait(1);
  }

The way AGS works no other player interaction (whether on room objects, or gui) can be run while there's a script function running.
Wait() function lets engine to update and redraw the game, but player clicks on objects will not be handled.
In order for interactions to work again you must exit the previous function first.

The solution for this, and any similar case, is to split the sequence into 2 parts: one before waiting for player input and one after.
For example: play only the first part in the function "wastebasket_Interact", and the second part in the function oInsideWasteBasket_Interact.

eri0o

Hey, if you name all your views in the Editor as VIEW_NAME, where name is what you want, say VIEW_CLARA_MAIN_CABIN, then you can type VIEW in the AGS Editor and it will show all views in the autocomplete. This should make it easier to know your views when you need one to input somewhere.

SMF spam blocked by CleanTalk