AGS v2.71: Custom function not working anymore (SOLVED)

Started by Kinoko, Thu 26/01/2006 13:26:53

Previous topic - Next topic

Kinoko

I'm so sick of this function giving me trouble. *sigh* Anyway.

I've noticed that most of my TypeLine functions have stopped working properly. The code has -not- been touched, and the only change has been that I've started using v2.71. The thing is, I can't figure out why that, if it is indeed that reason, would make any difference.

I have several slightly different custom TypeLine functions. One of them still works, and the rest don't.

This is the one that still works:

Code: ags

function TypeLineInvis (const string say, int xpos, int vpos, int width, int queue, int delay, int wait) {
if (IsGamePaused()==0) {
	StopMoving(EGO);
	SetTextWindowGUI(31);
	StrCopy(displayedline,"");
	StrCopy (line, say);
	typecount=0;
        textid = CreateTextOverlay(xpos, 100, 400, 1, 1, displayedline);
	length=StrLen(line);
	SetTimer(6, delay);
	delaya=delay;
	vposa=vpos;
	xposa=xpos;
	waita=wait;
	widtha=width;
	cue=queue;
	}
}


in repeatedly_execute_always:

Code: ags
if (IsTimerExpired(6)) {
	  if (typecount<length) {
	    StrFormat(displayedline, "%s%c", displayedline, StrGetCharAt(line,typecount));
	    SetTextOverlay(textid,xposa,vposa,widtha,1,1,displayedline);
	     if (StrGetCharAt(line,typecount)!=' ') PlaySound(1);
	     typecount++;
	     if (typecount==length) {
	       if (waita>0) SetTimer(7, waita);
	       else RemoveOverlay(textid);
	       } 
             else {
	       SetTimer(6, delaya);
	       }
	  }
}
else if (IsTimerExpired(7)) {
  RemoveOverlay(textid);
  SetTimer(5, 40);
}


This is one that won't work (the rest are all very similar to this one)

Code: ags

function TypeLineSay (const string say, int xpos, int vpos, int width, int delay, int wait) {
if (IsGamePaused()==0) {
	StrCopy (line, say);
	
	StopMoving(EGO);
	SetTextWindowGUI(1);
	  textid = 0;
	  length = 0;  
	  int i=0; 
	  StrCopy(displayedline,"");
	  textid = CreateTextOverlay(xpos, 100, 400, 1, 1, displayedline);
	
		  //get string length, to know how long the loop must run
	  length=StrLen(line); //set string length
		 //start loop
	while((i<length) && (1||(WaitKey(delay)==0))) {
		 // pick character at position "i"and stick it at the end of string "displayed line"
	    StrFormat(displayedline, "%s%c", displayedline, StrGetCharAt(line,i));
		 //set textoverlay as displayedline
	    SetTextOverlay(textid,xpos,vpos,width,1,1,displayedline); 
	
		 // if a space is added to the string do not play a sound, else play a 'tick'
	    if (StrGetCharAt(line,i) == ' '){
	   }
	   else{
		PlaySound(1);
	    }
		   //increase the loop counter
	    i++;  
	   if (i==length) if (wait>0) WaitKey(wait);
	   else if (wait == -1) while (IsKeyPressed(keyx) == 0) Wait(1);
	   }
	 RemoveOverlay(textid);
	 Wait(5);
}
}


The functions are working, but the second example isn't "typing out", the full text just appears straight away, no matter what I set the 'delay' as. So, I think that delay is the problem, but... I have no idea why.

SSH

This is your problem:

Code: ags

1||(WaitKey(delay)==0)


The new version now has "lazy evaluation" which means that if the first part of an "OR" experrsion is true, it doesn't bother evaluating the other parts. Either change this to:

(WaitKey(delay)==0)||1

or turn off lazy evaluation on the main editor setting panel.


Also, you might like to look at the code in my credits module which has a typewriter function in it, too...
12

Kinoko

#2
Thanks SSH! God, I was hoping it was just a change in the new code... BIG relief.

Well, I'll give it a look sometime but this function has been tweaked many, many times to suit all my nit-picky little needs...

EDIT: How do I turn off lazy evaluation? I don't see anything about it in the settings.

Gilbert

Quote from: Kinoko on Fri 27/01/2006 00:18:40
EDIT: How do I turn off lazy evaluation? I don't see anything about it in the settings.

Unfortunately seems that it's impossible to turn it off.
So if you want something like if (a==xx||b==yy) {
where b is an action which must be executed you may swap it to if (b==yy||a==xx) {

In case that you need both a and b actions to be executed you may do:

int k=b;
if (a==xx||k==yy) {

Kinoko

Ah k, thanks.

Might I make that a suggestion for future AGS releases then? A toggle for lazy evaluation?

SSH

At least the manual should mention it... the 2.71 upgarde guide says nothing of it (nor the rest of the manual)
12

Pumaman

Quote from: Kinoko on Fri 27/01/2006 10:51:50
Might I make that a suggestion for future AGS releases then? A toggle for lazy evaluation?

I'm not sure, to be honest. I would say the lack of lazy evaluation in the older versions was a defect, rather than adding it being a new feature. All other programming languages use the "lazy evaluation" approach, and this change pulls AGS in line with them.

Generally you shouldn't use functions with side effects in a while() or if() clause, but I understand that in situations like this it's a workaround for the lack of a "break" keyword.

QuoteAt least the manual should mention it... the 2.71 upgarde guide says nothing of it (nor the rest of the manual)

It's always difficult with a rather obscure change like this, to know how much to document it. Provide too much information and it will confuse people who don't need to know; but provide insufficient information and it can cause probelms like this.

SMF spam blocked by CleanTalk