Possible to run a dialog while a script is running in AGS 2.72? [SOLVED]

Started by auriond, Fri 14/11/2008 04:43:26

Previous topic - Next topic

auriond

I've done a search on the forum, and all answers seem to point to yes - if you use character.SayBackground and timers. Somehow though, I'm not getting the hang of it. I'm trying to do something like this:

- Enter room. TV image fades on.
- Characters have a dialog. TV image flickers in the background.
- Characters end dialog. TV image fades out. Exit room.

Currently I've set the TV image as a character, with the thought that if I can't animate the image using a script, I could use character views instead. I did manage to make fade in after the player enters the room, and then make it randomly flicker using the following script in the room's repeatedly_execute:

Code: ags
int trans = cTV.Transparency;
	while (trans <= 30) {
	  int ran = Random(30);
	  cTV.Transparency = ran;
	  Wait(3);
	}    


That gives it the very nice random-looking flicker that I was looking for. Then I turn my attention to running the dialog and fading it out, and that's where everything went to pot. Now the TV image fades in, barely flickers and the characters barely say anything before everything fades out. To make things worse, the characters are speaking at the same time!

For reference, here's the code I'm using:

Code: ags
// room script file

import int modeBeforeWait;

#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for Room: Player enters room (after fadein)

modeBeforeWait = mouse.Mode;
mouse.Mode = eModeWait;

// TV image fades in
Wait(30);
int trans = cTV.Transparency;
		while (trans > 0) {
			trans--;
			cTV.Transparency = trans;
			Wait(1);
		}  

cGirl1.SayBackground("What do you think?");
cGirl2.SayBackground("It's gorgeous!");

mouse.Mode = modeBeforeWait;
player.ChangeRoom(56);  

}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_b  // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
  // script for Room: Player enters room (before fadein)
cTV.Transparency = 100;  
}
#sectionend room_b  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_d  // DO NOT EDIT OR REMOVE THIS LINE
function room_d() {
  // script for Room: Player leaves room
  
// TV image fades out
int trans2 = cTV.Transparency;
		while (trans2 < 100) {
			trans2++;
			cTV.Transparency = trans2;
			Wait(1);
		}  

 
}
#sectionend room_d  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart room_c  // DO NOT EDIT OR REMOVE THIS LINE
function room_c() {
  // script for Room: Repeatedly execute

// TV image flickers
int trans1 = cTV.Transparency;
	while (trans1 <= 30) {
	  int ran = Random(30);
	  cTV.Transparency = ran;
	  Wait(3);
	}    

}
#sectionend room_c  // DO NOT EDIT OR REMOVE THIS LINE


I know I'm supposed to implement timers somewhere for this to work, but I just can't figure it out. Help?

Trent R

Not sure, but my ideas/comments are:

*Characters talking at the same time is supposed to happen with the SayBackground.
*I could be wrong, but I don't see why you don't use just the normal Speech command?
*If it's because you want the TV flickering in the background, try putting the flicker script under repeatedly_execute_always so that it will run even during a blocking function (ie. speaking)
*Check out the char.Speaking and char.Animating functions (readonly) to check for anything else you want to do
*Why the non-descriptive function names?

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

auriond

Thanks Trent!

- I figured the characters talking at the same time was supposed to happen with SayBackground, which is why I thought I needed to put timers in somewhere - to stop the fadeout from happening before the characters have had their say, and also to time the conversation right.
- Using the normal Say command stops the flickering from working.
- Putting the flickering script in the repeatedly_execute_always results in an error that says there's a call to a blocking function (i.e. the Wait command). Taking away the Wait command results in yet another error, something about loop iterations without an update. 
- char.Animating functions basically means I'll have to turn the flickering TV image into a looping character view. I liked it better as a random flicker. I'll do that if I fail to get this script to run concurrently with the dialog, though.

Not sure what you meant by the non-descriptive function names?

Dualnames

---I've put the lines I've changed in BOLD, so they're more clear and I've added some comments(//).




// room script file

import int modeBeforeWait;

[b[int timeloops[10];//we'll use this array integers to make sure background speech stays a little bit on screen[/b]

#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for Room: Player enters room (after fadein)

modeBeforeWait = mouse.Mode;
mouse.Mode = eModeWait;

// TV image fades in
Wait(30);
int trans = cTV.Transparency;
while (trans > 0) {
trans--;
cTV.Transparency = trans;
Wait(1);


cGirl1.SayBackground("What do you think?");//These two lines will be displayed in the same time(it would appear this way, actually they will be displayed within a two loops)

//so we add that integer
while (timerloop[0]<40) {
timerloop[0]++;
}

cGirl2.SayBackground("It's gorgeous!");

while (timerloop[2]<40) {
timerloop[2]++;
}

mouse.Mode = modeBeforeWait;
player.ChangeRoom(56); 

}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_b  // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
  // script for Room: Player enters room (before fadein)
cTV.Transparency = 100; 
}
#sectionend room_b  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_d  // DO NOT EDIT OR REMOVE THIS LINE
function room_d() {
  // script for Room: Player leaves room
 
// TV image fades out
int trans2 = cTV.Transparency;
while (trans2 < 100) {
trans2++;
cTV.Transparency = trans2;
Wait(1);



}
#sectionend room_d  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart room_c  // DO NOT EDIT OR REMOVE THIS LINE
function room_c() {
  // script for Room: Repeatedly execute

// TV image flickers
int trans1 = cTV.Transparency;
while (trans1 <= 30) {
timerloop[1]=0;
  int ran = Random(30);
  cTV.Transparency = ran;
// Wait(3);
while (timerloop[1]!=3) {//probably you should need to increase this around to 20
timerloop[1]++;
}//Now you can add this to repeatedly execute always.

}   

}
#sectionend room_c  // DO NOT EDIT OR REMOVE THIS LINE
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

auriond

Thanks Dualnames. That looks much better than my code, but when I tried it out it still gave me that error about looped iterations:

QuoteError: run_rep_exec: error -6 (Error: Script appears to be hung (150001 while loop iterations without an update) in Room 59 script (line 68) ) running function 'repeated_execute_always'

Line 68 is the end of the timerloop code in that section.

Dualnames

Quote from: auriond on Fri 14/11/2008 12:50:45
Thanks Dualnames. That looks much better than my code, but when I tried it out it still gave me that error about looped iterations:

QuoteError: run_rep_exec: error -6 (Error: Script appears to be hung (150001 while loop iterations without an update) in Room 59 script (line 68) ) running function 'repeated_execute_always'

Line 68 is the end of the timerloop code in that section.

Yep, I noticed that. If you could be precise in which timerloop that is? I mean it's an array.
Also I've declared it as timeloops..so you probably noticed that. Well instead of the two loops go ahead and use a wait command.

Well, the time loops thing does this:
it increases an integer value(thus running one game loop)
put a display (" Time loop
  • :%d",timerloop[0]);
    to see if indeed the integer is increasing.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

auriond

That's the thing, the Wait command doesn't work in the repeatedly_execute_always section because it's a "blocking function". Line 68 is basically the end of the repeatedly_execute_always section. I don't know what else to do.

Dualnames

So the rest of the timerloops work good?
Try and comment the repeatedly execute to see if the timerloops are working.
As for the repeatedly execute regardless of the after fade in loops

function repeatedly_execute_always() {

int trans1 = cTV.Transparency;
while (trans1 <= 30) {
if  (timerloop[1]!=3) {
timerloop[1]++;
return;
}
timerloop[1]=0;
int ran = Random(30);
cTV.Transparency = ran;
}
}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

auriond

Without the code in repeatedly_execute, the lines now stay on screen long enough to be read. But they still show up together, although Girl1's line disappears just before Girl2's line does. Tweaking the numbers on the timerloop code after Girl1's line just makes Girl2's line last longer. But yeah, it's a definite improvement on what I was doing.

The new code for repeatedly_execute works GREAT! It actually flickered about 2 second before fading out. Thanks so much for that. I'm gonna tweak it some more to see if I can get the lines to come in one after the other, now.

Edit: The Say command works now with the image flickering in the background! This is fantastic. Thank you so much Dualnames, you've solved it!

SSH

Can I just check: are you using AGS 3.1 where the ability to run scripts during dialogs was added?
12

auriond

Oh sorry! Nope - I'm still using 2.72. I'll change the thread title to reflect this for future reference.

Dualnames

Quote from: auriond on Fri 14/11/2008 13:35:28
Edit: The Say command works now with the image flickering in the background! This is fantastic. Thank you so much Dualnames, you've solved it!

No trouble. At your service.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk