[SOLVED] Region Tint only working when walking and not "interacting"?

Started by Rik_Vargard, Mon 10/01/2022 21:09:49

Previous topic - Next topic

Rik_Vargard

Hello!

So here's the thing:

- Player has to go talk to Character. (so there's a player.Walk script, to x and y coordinates, to get to Character)
- While walking to Character, Player walks through Region 1
- Region 1 has a tint script (walks onto/off) .... (I also added a region [1].Tint(..) in room_RepExec because of testing the thing)

Player >>walks>> REGION 1 >>walks>> Character

Now:

- When Player "Walks" to Character and going through Region 1 everything works perfectly. Player is tinted.
- When Player "Talks/Interacts" with Character , Player will walk to coordinates, but when passing through Region 1, Tint will not work.

My guess is that the Region Tint doesn't work because the game is technically paused while Player is Walking to the x,y coordinates to Talk to Character.

Any ideas on how to fix this, if it's possible?



eri0o

Regions can have a specific tint value directly in it's properties.

If you don't want to use this method, you can try using Region.GetAtRoomXY() to read the Region on a repeatedly_execute_always loop. A repeatedly_execute_always will execute it's contents regardless of the game being paused or not so the value changes should happen without issues.

Crimson Wizard

#2
Yes unfortunately there's this issue, that script events are not called during blocking actions due to how script system works in AGS. Therefore regions don't trigger "walk on/off" when there's a blocking walk.

Does it work if you just add Tint in the region's properties in the editor, as eri0o suggested?
Note that if you do that in script (region [1].Tint(..) ), try doing that in "room before fade-in" event instead of "repExec", as "repExec" also is not called during blocking actions.
Above of course refers to a case when region has constant Tint, which suppose to act all the time.

Note that if you need to use "walk on/off" events in some other circumstances, you may instead simulate blocking walk:
Code: ags

player.Walk(... eNoBlock);
while (player.Moving) Wait(1);

^ this code starts the non-blocking walk and then loops, waiting until player stops.
If you put this code in a custom function and call that function everytime instead of player.Walk, then you will probably get these and other events. The issue with this approach is that rep-exec will also work during these walks, so you may find a need to adjust the game logic there.

Pax Animo

Just a thought, so for give me if this makes no sense:

Would a walk to x, y off of the region. (give the blocking action time to be updated and switching the region tinting on) and then walk to x, y. not work?
*Not tested*

I comment because I'm having similar blocking actions issues.
I'm always interested with how the blocking code works.
Misunderstood

Crimson Wizard

#4
Quote from: Pax Animo on Tue 11/01/2022 00:28:10
Would a walk to x, y off of the region. (give the blocking action time to be updated and switching the region tinting on) and then walk to x, y. not work?

The thing is, you order player to walk to certain object. If you also need to separately walk them to the region first, then you will have to calculate their path intersection with that region to find out whether they will cross the region at all, and at which point. AGS currently does not provide enough information about character's walk paths, but even if it did, that would be extra scripting work compared to the other solutions.

If other solutions don't work for some reason, then it's easier to just test whether character is crossing the region in repeatedly_execute_always.

Rik_Vargard

All right!! Thank you guys so much for the replies :)

I tried all that and some more + RTFM and thanks to your inspiration I worked it out.
And no need for the UseColorTint in the Region's properties.

I entered this code in the room script:
Code: ags

function repeatedly_execute_always()
{
  region[1].Tint(245, 161, 237, 50, 100);
  region[2].Tint(200, 245, 245, 50, 10);
  region[3].Tint(140, 245, 240, 30, 100);
}


But this works only if Player has no current tint. If Player is on a region with a tint it won't work; it will keep that tint during the whole walk.

So: Before every Walk script, I put a player.RemoveTint(), just like this:
Code: ags

function cJohn_Talk()
{
  player.RemoveTint();
  player.Walk(1300, 1050, eBlock, eWalkableAreas);
  player.FaceDirection (eDirectionRight);
}


I'm guessing that since Player is in a region with a tint (always). He has it removed and then gets tinted again in a fraction of a second.
The fact that in that fraction, he loses the tint makes the  repeatedly_execute_always work.

It's funny to see how sometimes an epic search has a simple solution at the end.  :P


And I wouldn't have found it without you guys so thank you so much again!

Cheers!






Crimson Wizard

I still think that's a mistake that you are applying a tint to the region in the repeatedly_execute_always. There should not be a need to do that. Your code sets exactly same tint configuration to the 3 regions multiple times per second, over and over again. Instead, you could simply do that once, in room's "before fade-in" event. Or even simplier - in the region properties.

EDIT: Also, it's curious how calling player.RemoveTint() might change anything.

Thing is, there are two kinds of tints: 1) explicit character's tint, which is unrelated to regions, and 2) the tint it gets from the regions. The Character may get either one or another, but not both at the same time.
player.RemoveTint() removes character's explicit tint, which is normally set using Character.Tint script function. It should not remove region's tint.
Could it be that character was tinted by command previously in your script? That's the only reason I know why RemoveTint would affect anything. Which might also explain why the character was not tinted by the regions. Not sure if that makes sense, as I don't know much of a context of your game or room.

EDIT 2: Ahhhh.... you had this in the first post:
Quote from: Rik_Vargard on Mon 10/01/2022 21:09:49
- Region 1 has a tint script (walks onto/off)
Do you maybe still have this walk onto/off script, that adds explicit tint to the player?
If yes, then this would mean that you have conflicting tints that the game will try to apply to the character: one by script command, and another from the region properties.

Rik_Vargard

QuoteI still think that's a mistake that you are applying a tint to the region in the repeatedly_execute_always. There should not be a need to do that. Your code sets exactly same tint configuration to the 3 regions multiple times per second, over and over again. Instead, you could simply do that once, in room's "before fade-in" event. Or even simplier - in the region properties.

You're right, thanks for that, it works when I put it in Room Load (it's easier to copy/paste than the properties)


As for the rest, I don't really know why it works.

Thing is: If Player has a tint (or not) , its all the same, it won't work without player.RemoveTint() before the Walk script.
In addition, I do have the normal onto/out scripts in there as well
Code: ags

function region1_WalksOnto()
{
  player.Tint(245, 161, 237, 50, 100);
}
function region1_WalksOff()
{
  player.RemoveTint();
}


So when a player is on a region with a tint, clicking to Talk on a character at the other end of the room will make Player walk while keeping that tint (not removed even if in the Region script as you can see)
The only thing that works is when I put that player.RemoveTint() line before the Walk script.

I don't know, this is how I made it work :p

And just for info, here's the room script:

Spoiler

Code: ags

function room_FirstLoad()
{
 int i = Random(4);
 
 if (i == 0) Channel = aIntro01.Play(eAudioPriorityNormal, eOnce);  
 if (i == 1) Channel = aIntro02.Play(eAudioPriorityNormal, eOnce);
 if (i == 2) Channel = aIntro03.Play(eAudioPriorityNormal, eOnce);
 if (i == 3) Channel = aIntro03.Play(eAudioPriorityNormal, eOnce);
 if (i == 4) Channel = aIntro04.Play(eAudioPriorityNormal, eOnce);  
}

function room_Load()
{
  region[1].Tint(245, 161, 237, 50, 100);
  region[2].Tint(200, 245, 245, 50, 10);
  region[3].Tint(140, 245, 240, 30, 100);
  
  cDarcy.Tint(140, 245, 240, 30, 100);
  cDarcy.Transparency = 0;
  Channel.Volume = 80;
  Channel2.Volume = 100;
  
  if (Look == 1)
  {
    cDarcy.ChangeView(3);
  }
}

function room_AfterFadeIn()
{
  player.SetWalkSpeed (25, 15);
}

function hHotspot1_WalkOn()
{
  player.ChangeRoom (5, 230, 1010, eDirectionRight);
}

function hHans_Talk()
{
  player.RemoveTint();
  player.Walk(1175, 950, eBlock, eWalkableAreas );
  player.FaceDirection (eDirectionRight);
  player.ChangeRoom(8, 800, 830, eDirectionLeft);
}
function hJimmy_Talk()
{
  player.RemoveTint();
  player.Walk(585, 900, eBlock, eWalkableAreas);
  player.FaceDirection (eDirectionLeft);
  player.ChangeRoom(7, 1600, 920, eDirectionLeft);
}


function hPoliceEntrance_Interact()
{
  player.RemoveTint();
  player.Walk (185, 815, eBlock, eWalkableAreas);
  player.FaceDirection (eDirectionUp);
  player.ChangeRoom(10, 460, 1000, eDirectionRight);
}

function room_RepExec()
{
   if ((Channel == null) || !Channel.IsPlaying)
        {
          int i = Random(4);
          if (i == 0) Channel = aIntro01.Play(eAudioPriorityNormal, eOnce);
          if (i == 1) Channel = aIntro02.Play(eAudioPriorityNormal, eOnce);
          if (i == 2) Channel = aIntro03.Play(eAudioPriorityNormal, eOnce);
          if (i == 3) Channel = aIntro03.Play(eAudioPriorityNormal, eOnce);
          if (i == 4) Channel = aIntro04.Play(eAudioPriorityNormal, eOnce);
        }
        Channel.Volume = 80;  
}

/////////////////////////////////////////////REGIONS

function region1_WalksOnto()
{
  player.Tint(245, 161, 237, 50, 100);
}
function region1_WalksOff()
{
  player.RemoveTint();
}

function region2_WalksOnto()
{
  player.Tint(200, 245, 245, 50, 10);
}
function region2_WalksOff()
{
  player.RemoveTint();
}

function region3_WalksOnto()
{
  player.Tint(140, 245, 240, 30, 100);
}
function region3_WalksOff()
{
  player.RemoveTint();
}
[close]

Crimson Wizard

Quote from: Rik_Vargard on Tue 11/01/2022 17:07:16
And just for info, here's the room script:

Right, see, you have both kinds of tints used here.

1) Your regions have an active tint. You configure it by calling "region[1].Tint", and so on, in the Room_Load. This is the tint that is supposed to be automatically applied to any character or object which passes through these regions, and automatically removed when they leave the region.

2) But besides that, you are also assigning an explicit tint to the character, in "region1_WalksOnto" function (and similar for other regions).

So, my suggestion is: remove these walk on / off event functions altogether, and remove a call to player.RemoveTint() too. Then only the automatic region tint will work, and there will be no conflict between tint types.

Rik_Vargard

So I removed walk on / off event functions and all of the  Remove.Tint lines, only left with the region[1].Tint  in Room_Load

And I'm back where I started: it doesn't work. Back to post 1.

Perhaps I'm not explaining very well, sorry :p

- Player is on a Region that has a Tint. let's say Blue.
- I click on Character with the Talk Icon so Player has to walk over there to start the dialog. (So the game is "blocked" right?)
- While Player walks to Character, Player stays Blue, even if obviously leaving the Region, and even if walking through another Region with another Tint on the way there.

So what I did is the only way I could make it work.
I'd really like to know how and why it works but I dont.

PS: I could share the game files if you ever needed it.

Crimson Wizard

I understand your explanation, but what you describe is not supposed to happen.

Here, I made a quick test game that simulates this situation. There's a small room with 3 tinted regions, and a second character. Player begins standing on one of the regions (tinted).
If you Interact with the character (the "Hand" verb), the player will blocking walk there, through 3 different regions. And the tint changes as he walks:

https://www.dropbox.com/s/kiabg7cn7wvnwo6/test--regiontints.zip?dl=0


So maybe something else affects your player's tint? Could you post that variant of a room script?

Quote from: Rik_Vargard on Tue 11/01/2022 17:46:42
PS: I could share the game files if you ever needed it.

Yes, I may take a look, because this is very curious.

Rik_Vargard

All right, well well, Sir Crimson Wizard, or should I say Master. It looks like your mystery has become mine.

After looking at your test game, I have teared down my game, deleting everything, and everything, aaaand everything down to have the game start in just that room, to have the same as your test game.
And it works, you're right. So I told myself it should come from the previous room and so i removed all onto/out tints and RemoveTints etc and now everything works like you told me all along.

So I've been thinking why and how and I have that one last question coming up:

I did start a new Game.
Is it possible that it was a Save Game problem?
I do save my game at some point to not have to start it all over again.
I do it like two or three rooms before that infamous room with the region tints where I made the changes.
AGS will crash if I load a saved game and there are scripting problems because of changes.
Since AGS doesn't crash and I'm three rooms away, I suppose that whatever new script I put in that room will run like normal.

Could it be that AGS doesn't crash every time you make some changes, but the changed game scripts (like Tint here) are not working ?



Crimson Wizard

Well, yes, if you restored a save where your character already had a tint applied, then it will keep that tint.

Quote from: Rik_Vargard on Tue 11/01/2022 19:22:19
Could it be that AGS doesn't crash every time you make some changes, but the changed game scripts (like Tint here) are not working ?

There are changes that break saves and changes that do not break saves. In regards to scripts, only changing global variables breaks saves (the variables that are outside of function), but changing functions does not.

Rik_Vargard

All right, so if only changing Global variables breaks saves, I guess some mystery will still be there somewhere because I saved in a room before the Tint thing is even a thing... and how I did what I did and make it work   :shocked: :confused:  :P

Anyway, I have absolutely no words to thank you enough for taking all this time and effort on this topic!

I am a very honored noob.

Cheers!

SMF spam blocked by CleanTalk