A thing on REGIONS and another one on Repeatedly_execute

Started by DiegoHolt, Mon 20/01/2025 23:32:40

Previous topic - Next topic

DiegoHolt

Hi you all, hope you're all doing great and having a wonderful 2025 so far.

I know you like to go straight to the point, so here it is:

1- I have some regions with things happening when the player walks on and off. The thing is that when you're inside that region and the event is triggered (playing a sound, i.e) if the player clicks on a hotspot that changes the room, then the 'walk off' code is ignored and the event continues as if you were still inside that region (the room changes and the sound keeps playing even when you've left the region) The same happens if you click that hotspot from outside the region, because the player passes through it when going to that room exit and the event isn't triggered.

The code is pretty basic:

Code: ags
function region2_WalksOnto(Region *theRegion)
{
  if (diabloProteccion == 0)
  {
    aHumming.Play(eAudioPriorityNormal, eRepeat);
  }
}

function region2_WalksOff(Region *theRegion)
{
  if (haloProtege == 1)
  {
    tiempoHalo = 0;
    aHumming.Stop();
  }
}

-------

2- In the main screen, I want a character to appear after some time of -no button clicked-, so I've set a timer when the intro is over and put a wait for a key:

Code: ags
SetTimer(2, 120);
  WaitInput(eInputKeyboard + eInputMouse, -1);

and then:

Code: ags
function room_RepExec()
{
   if (IsTimerExpired(2))
      {
       etc...

But the animation never starts when the time is expired.

-------

I'm guessing the first one has been solved already, but I couldn't find it in the forums.

As always, thank you for your time!  :-D

glurex

Hi!

Regarding problem N°1, have you checked the "room_Leave" function?

e.g. (using your code)

Code: ags
function room_Leave()
{
 if (haloProtege == 1)
  {
    aHumming.Stop();
    tiempoHalo = 0; 
}
}

Remember to link the event in the Room Editor.

Crimson Wizard

Quote from: DiegoHolt on Mon 20/01/2025 23:32:401- I have some regions with things happening when the player walks on and off. The thing is that when you're inside that region and the event is triggered (playing a sound, i.e) if the player clicks on a hotspot that changes the room, then the 'walk off' code is ignored

So, from my memory, these region events are not run during blocking actions, which makes them unusable with the blocking Walk. You have to either make walk non-blocking (and run a while loop with Wait(1) if you like to wait until it finishes), or use some other way to detect walking in/out the location.

Khris

2 is an easy fix: you passed -1, so the WaitInput() command blocks script execution and therefore repeatedly_execute / room_RepExec.
Use this instead:

Code: ags
  // after intro has played
  if (WaitInput(eInputKeyboard + eInputMouse, 120) == 0) { // ended by timeout
    // non-blocking animation goes here
    WaitInput(eInputKeyboard + eInputMouse, -1);
  }

If the player does nothing, this will wait for 3 seconds, play the animation, then pause the script until input.
If the player clicks / types during the first 3 seconds, it will skip the animation and the indefinite wait.

Regarding 1, you need to detect the region events yourself. This can be done using repeatedly_execute_always and a variable:

Code: ags
void EnterRegion(int id) {
  if (id == 2) {
    if (diabloProteccion == 0)
    {
      aHumming.Play(eAudioPriorityNormal, eRepeat);
    }
  }
}

void LeaveRegion(int id) {
  if (id == 2) {
    if (haloProtege == 1)
    {
      tiempoHalo = 0;
      aHumming.Stop();
    }
  }
}

Region* prevRegion;

function repeatedly_execute_always() {
  Region* currRegion = Region.GetAtRoomXY(player.x, player.y);
  if (currRegion != prevRegion) {
    // player's region changed
    if (prevRegion.ID > 0) LeaveRegion(prevRegion.ID);
    if (currRegion.ID > 0) EnterRegion(currRegion.ID);
  }
  prevRegion = currRegion;
}

SMF spam blocked by CleanTalk