text overlay trouble with obsolete functions[SOLVED]

Started by spook1, Mon 03/04/2006 20:21:05

Previous topic - Next topic

spook1

I use the script for typewriter style credits (one letter at a time).

The function I use for this is :
Code: ags


function TypeLine(string line, int vspacing){
Ã,  
Ã,  int length=0;
Ã,  int i = 0;
Ã,  string displayedline;

Ã,  int textid = 0;

Ã,  length = 0;Ã,  
Ã,  i=0; 
Ã,  StrCopy(displayedline," ");
Ã,  
Ã,  textid = CreateTextOverlay(xpos,50,400,font,colour,displayedline);

Ã,  length=StrLen(line); //set string length
Ã,  while(i<length){
Ã,  Ã,  
Ã,  Ã,  StrFormat(displayedline, "%s%c", displayedline, StrGetCharAt(line,i));
Ã,  Ã,  SetTextOverlay(textid, 10,vspacing,400, font, colour, displayedline);

Ã,  Ã,  if (StrGetCharAt(line,i) == ' '){
Ã,  Ã,  Ã,  Wait(10);
Ã,  Ã,  }
Ã,  Ã,  else{
Ã,  Ã,  Ã,  PlaySound(1);
Ã,  Ã,  Ã,  Wait(5);
Ã,  Ã,  }
Ã,  Ã,  i++; 
Ã,  }
Ã,  return textid;
}



I seem to have to replace the CreateTextOverlay function by
static Overlay* Overlay.CreateTextual(int x, int y, int width,
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int font, int color, string text)

according to the help files.

I do not know what to do with this code snip ??
What does a star mean? How do I declare, define, adjust my function??

Any help would be greatly appreciated since I have stumbled over this before.
I was quite fluent in the old script, but now I get confused over and over again....
But I'll learn how to overcomeÃ,  :-P

RickJ

Quote
I do not know what to do with this code snip ??
What does a star mean? How do I declare, define, adjust my function??
The star '*' means that the variable is a pointer.    In this case it is a pointer to the overlay.   You can think of the overlay as consisting of several variables, such as font, color, width, text, etc.    In general when you define  "Overlay *TextOverlay;"  then you can use things like "TextOverlay.Font=1" to access these different variables.   These variables can be published in which case you can access them otherwise they are private and hidden from you.  Sometimes you can just acces them as a variable and sometimes you need to use a function to access them as in "TextOverlay.SetText("Hello");.

Quote
Any help would be greatly appreciated since I have stumbled over this before.
I was quite fluent in the old script, but now I get confused over and over again....
But I'll learn how to overcome  :-P
It will take a little getting used to but in the long runn you will realize that the new way is much simpler.  I have taken the liberty of converting the code snippet to AGS 2.72 but I haven't had a chance to test it, so there is a good chance of bugs. 

Code: ags

Overlay *TypeLine(String line, int vspacing){
 
   int length=0;
   int i = 0;
   String displayedline;
   int textid = 0;
   Overlay* textoverlay;

  length = 0; 
  i=0;
  displayedline = " ";
 
   textoverlay = Overlay.CreateTextual(xpos,50,400,font,color,displayedline);

   length = line.Length;  //set string length
   while(i<length){
   
       displayedline = displayedline.AppendChar(line.Chars[i]));
       SetTextOverlay(textid, 10,vspacing,400, font, colour, displayedline);
       myoverlay.SetText(400,font,colour,displayedline);

      if line.Chars[i]== ' ') {
         Wait(10);
      }
      else{
         PlaySound(1);
         Wait(5);
      }
      i++;
   }
   return textoverlay;
}


The function used to return the overlay's numerical id but now it returns a pointer to the overlay.  I'm guessing that there is a RemoveOverlay() function elsewhere in your script.  So what you would do there is  something like this.

Code: ags

// At the top of the script
Overlay *textoverlay;
:
// Somewhere in your script
textoverlay = TypeLine(String line, int vspacing);
:
// Somewhere else in the script
textoverlay.RemoveOverlay();


Try this out and let me know if it works for you.  If not I'llwork on it more tomorrow.

Cheers
RickJl

spook1

Thanks a lot!!
In university I took a course in pascal programming. But I never got to the pointers- it was for the advanced curse ;-)
So now my time has come.

This code was also published in the technical archive, so once I worked it out, I'll publish it also there,

Regards,

Martijn

spook1

#3
OK, I played around with the code, now it works fine.


Code: ags

// room script file
Overlay *textoverlay;


Overlay *TypeLine(String line, int vspacing){

Ã,  Ã, int length=0;
Ã,  Ã, int i = 0;
Ã,  Ã, String displayedline;
Ã,  Ã, int textid = 0;
Ã,  Ã, int colour = 0;
Ã,  Ã, int font = 0;
Ã,  Ã, int xpos = 20;
Ã,  
Ã,  Ã, 
Ã,  Ã, 
Ã,  length = 0; 
Ã,  i=0;
Ã,  displayedline = " ";

Ã,  Ã, textoverlay = Overlay.CreateTextual(xpos,50,400,font,colour,displayedline);

Ã,  Ã, length = line.Length;Ã,  //set string length
Ã,  Ã, while(i<length){
Ã,  Ã, 
Ã,  Ã,  Ã,  Ã, displayedline = displayedline.AppendChar(line.Chars[i]);
Ã,  Ã,  Ã,  Ã, // SetTextOverlay(textid, 10,vspacing,400, font, colour, displayedline);Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  //!!!!!!!!!!!!!!!!!!changed by spook1
Ã,  Ã,  Ã,  Ã, textoverlay.SetText(400,font,colour,displayedline);Ã,  //!!!!!!!!!!!!!!!!!!changed by spook1


Ã,  Ã,  Ã,  if (line.Chars[i]== ' ') {
Ã,  Ã,  Ã,  Ã,  Ã, Wait(10);
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else{
Ã,  Ã,  Ã,  Ã,  Ã, PlaySound(1);
Ã,  Ã,  Ã,  Ã,  Ã, Wait(5);
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  i++;
Ã,  Ã, }
Ã,  Ã, return textoverlay;
}


#sectionstart region1_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function region1_a() {
Ã,  // script for Region 1: Player walks onto region
cEgo.ChangeRoom(6,196, 225);Ã,  
}
#sectionend region1_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
Ã,  // script for Room: Player enters room (before fadein)
gHeartbeat.Visible = false;
gSimlektogui.Visible =true;
Ã,  
}
#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: First time player enters room
Ã,  
textoverlay = TypeLine("Testtext",10);
}
#sectionend room_bÃ,  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_cÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_c() {
Ã,  // script for Room: Player leaves room
Ã,  
textoverlay.Remove();
}
#sectionend room_cÃ,  // DO NOT EDIT OR REMOVE THIS LINE






SSH

12

spook1

I looked into it, but I cannot get it to work.
Do you have an example of it??

[edit]
Hmm, I already found it : http://www.lumpcity.co.uk/~ssh/credittest.rar

SMF spam blocked by CleanTalk