Jibble

Author Topic: [SOLVED] Region Tint only working when walking and not "interacting"?  (Read 500 times)

Rik_Vargard

  • Hello from Belgium!
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?


« Last Edit: 11 Jan 2022, 16:13 by Rik_Vargard »

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.

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: Adventure Game Studio
  1. player.Walk(... eNoBlock);
  2. while (player.Moving) Wait(1);
  3.  
^ 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.
« Last Edit: 10 Jan 2022, 23:52 by Crimson Wizard »

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.
« Last Edit: 11 Jan 2022, 00:37 by Pax Animo »
I'm a slow learner but I like to ask questions.

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.
« Last Edit: 11 Jan 2022, 01:14 by Crimson Wizard »

Rik_Vargard

  • Hello from Belgium!
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: Adventure Game Studio
  1. function repeatedly_execute_always()
  2. {
  3.   region[1].Tint(245, 161, 237, 50, 100);
  4.   region[2].Tint(200, 245, 245, 50, 10);
  5.   region[3].Tint(140, 245, 240, 30, 100);
  6. }
  7.  

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: Adventure Game Studio
  1. function cJohn_Talk()
  2. {
  3.   player.RemoveTint();
  4.   player.Walk(1300, 1050, eBlock, eWalkableAreas);
  5.   player.FaceDirection (eDirectionRight);
  6. }
  7.  

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!





« Last Edit: 11 Jan 2022, 16:14 by Rik_Vargard »

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:
- 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.
« Last Edit: 11 Jan 2022, 16:59 by Crimson Wizard »

Rik_Vargard

  • Hello from Belgium!
Quote
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.

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: Adventure Game Studio
  1. function region1_WalksOnto()
  2. {
  3.   player.Tint(245, 161, 237, 50, 100);
  4. }
  5. function region1_WalksOff()
  6. {
  7.   player.RemoveTint();
  8. }
  9.  

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: ShowHide

Code: Adventure Game Studio
  1. function room_FirstLoad()
  2. {
  3.  int i = Random(4);
  4.  
  5.  if (i == 0) Channel = aIntro01.Play(eAudioPriorityNormal, eOnce);  
  6.  if (i == 1) Channel = aIntro02.Play(eAudioPriorityNormal, eOnce);
  7.  if (i == 2) Channel = aIntro03.Play(eAudioPriorityNormal, eOnce);
  8.  if (i == 3) Channel = aIntro03.Play(eAudioPriorityNormal, eOnce);
  9.  if (i == 4) Channel = aIntro04.Play(eAudioPriorityNormal, eOnce);  
  10. }
  11.  
  12. function room_Load()
  13. {
  14.   region[1].Tint(245, 161, 237, 50, 100);
  15.   region[2].Tint(200, 245, 245, 50, 10);
  16.   region[3].Tint(140, 245, 240, 30, 100);
  17.  
  18.   cDarcy.Tint(140, 245, 240, 30, 100);
  19.   cDarcy.Transparency = 0;
  20.   Channel.Volume = 80;
  21.   Channel2.Volume = 100;
  22.  
  23.   if (Look == 1)
  24.   {
  25.     cDarcy.ChangeView(3);
  26.   }
  27. }
  28.  
  29. function room_AfterFadeIn()
  30. {
  31.   player.SetWalkSpeed (25, 15);
  32. }
  33.  
  34. function hHotspot1_WalkOn()
  35. {
  36.   player.ChangeRoom (5, 230, 1010, eDirectionRight);
  37. }
  38.  
  39. function hHans_Talk()
  40. {
  41.   player.RemoveTint();
  42.   player.Walk(1175, 950, eBlock, eWalkableAreas );
  43.   player.FaceDirection (eDirectionRight);
  44.   player.ChangeRoom(8, 800, 830, eDirectionLeft);
  45. }
  46. function hJimmy_Talk()
  47. {
  48.   player.RemoveTint();
  49.   player.Walk(585, 900, eBlock, eWalkableAreas);
  50.   player.FaceDirection (eDirectionLeft);
  51.   player.ChangeRoom(7, 1600, 920, eDirectionLeft);
  52. }
  53.  
  54.  
  55. function hPoliceEntrance_Interact()
  56. {
  57.   player.RemoveTint();
  58.   player.Walk (185, 815, eBlock, eWalkableAreas);
  59.   player.FaceDirection (eDirectionUp);
  60.   player.ChangeRoom(10, 460, 1000, eDirectionRight);
  61. }
  62.  
  63. function room_RepExec()
  64. {
  65.    if ((Channel == null) || !Channel.IsPlaying)
  66.         {
  67.           int i = Random(4);
  68.           if (i == 0) Channel = aIntro01.Play(eAudioPriorityNormal, eOnce);
  69.           if (i == 1) Channel = aIntro02.Play(eAudioPriorityNormal, eOnce);
  70.           if (i == 2) Channel = aIntro03.Play(eAudioPriorityNormal, eOnce);
  71.           if (i == 3) Channel = aIntro03.Play(eAudioPriorityNormal, eOnce);
  72.           if (i == 4) Channel = aIntro04.Play(eAudioPriorityNormal, eOnce);
  73.         }
  74.         Channel.Volume = 80;  
  75. }
  76.  
  77. /////////////////////////////////////////////REGIONS
  78.  
  79. function region1_WalksOnto()
  80. {
  81.   player.Tint(245, 161, 237, 50, 100);
  82. }
  83. function region1_WalksOff()
  84. {
  85.   player.RemoveTint();
  86. }
  87.  
  88. function region2_WalksOnto()
  89. {
  90.   player.Tint(200, 245, 245, 50, 10);
  91. }
  92. function region2_WalksOff()
  93. {
  94.   player.RemoveTint();
  95. }
  96.  
  97. function region3_WalksOnto()
  98. {
  99.   player.Tint(140, 245, 240, 30, 100);
  100. }
  101. function region3_WalksOff()
  102. {
  103.   player.RemoveTint();
  104. }
  105.  
« Last Edit: 11 Jan 2022, 17:16 by Rik_Vargard »

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.
« Last Edit: 11 Jan 2022, 17:15 by Crimson Wizard »

Rik_Vargard

  • Hello from Belgium!
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.
« Last Edit: 11 Jan 2022, 17:50 by Rik_Vargard »

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?

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

Yes, I may take a look, because this is very curious.
« Last Edit: 11 Jan 2022, 17:58 by Crimson Wizard »

Rik_Vargard

  • Hello from Belgium!
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 ?


« Last Edit: 11 Jan 2022, 19:43 by Rik_Vargard »

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

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

  • Hello from Belgium!
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!