Can I create credits that are in "being typed style"?
I mean: A text is printed ('being typed') on the screen letter by letter, while you hear the typewriter sounds in the background.
hHs this been done before in AGS?
regards,
Martijn
You could write a script to do it for you. Shouldn't be too difficult. Hmm... I suppose you want an example...
I would choose to do it using a GUI... but for that part, you could use any display method you want, you could use SetTextOverlay as in Strazer's example. You can get the theory from the rest of this code, which if you loop further and use arrays, you could get to do all of your credits in almost just this much code. I hope I did this right. I'm at work and I don't have AGS here.
string typecredits1; // the credit text
string typecredits1cut ; // the cut text
int typecredits1len; // the length of the credit text
int creditscounter=1; // to be used for the loop
StrCopy (typecredits1, "Example by Relight"); // sets what the credit will be
typecredits1len=StrLen(typecredits1); // sets length variable to the length of the string
GuiOn(x); // turn on a gui where you have a textbox
while (creditscounter != typecredits1len) { // starts the loop
Ã, StrCopy (typecredits1cut, typecredits1); // copies the original text to the cut text var
Ã, StrSetCharAt (typecredits1cut, creditscounter, 0); // will truncate the string
Ã, SetTextBoxText(x, y, typecredits1cut); // set textbox y on gui x to the cut text
Ã, PlaySound(x); // play the typewriter sound
Ã, Wait(5); // delay
Ã, creditscounter++; // increments the counter
Ã, }
I have this in my notes, it's from a post by Scorpiorus I believe:
Quoteint buffer = CreateTextOverlay(50,80,120,2,15,"P");
Wait(5);
SetTextOverlay(buffer,50,80,120,2,15,"Ps");
Wait(5);
SetTextOverlay(buffer,50,80,120,2,15,"Pss");
Wait(5);
SetTextOverlay(buffer,50,80,120,2,15,"Psst");
Wait(5);
SetTextOverlay(buffer,50,80,120,2,15,"Psst.");
Wait(5);
SetTextOverlay(buffer,50,80,120,2,15,"Psst..");
Wait(5);
SetTextOverlay(buffer,50,80,120,2,15,"Psst...");
Wait (80);
RemoveOverlay(buffer);
The above code would only work during interaction/cutscene modes because of
the blocking commands...
To have it during play, you'd need to change the Wait commands to a looping cycle or something.
Just put PlaySound commands in there and you're done.
Thanks a lot for the quick help. I have been trying to create a mix of both yoyr suggestions. I am afraid I am missing an essential property of obone of the string functions, since I keep getteing an error about comparing a string to a non-string in the following line: StrCopy(displayedline,StrCat(displayedline, StrGetCharAt(line,i) ) );
the complete function is copied below.
can you see quickluy what I am missing ( I am not a programmer, but trying to make the best of it ;-))
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){
StrCopy(displayedline,StrCat(displayedline, StrGetCharAt(line,i) ) );
i++;
SetTextOverlay(10,vspacing,400,2,10,displayedline);
Wait(5);
PlaySound(1);
}
return textid;
}
I'm not 100% sure, but I think you can't use displayedline twice like that.
Thanks,
I tried the followinfg script without a double 'displayedline' but that also fails, I changed the line into:
StrCopy(displayedline_new, StrCat(displayedline_old,StrGetCharAt(line,i)) );
The complete script:
function TypeLine(string line, int vspacing){
int length=0;
int i = 0;
string displayedline_new;
string displayedline_old;
int textid = 0;
length = 0;
i=0;
StrCopy(displayedline_old," ");
textid = CreateTextOverlay(xpos,50,400,font,colour,displayedline_new);
length=StrLen(line); //set string length
while(i<length){
StrCopy(displayedline_new, displayedline_old);
StrCopy(displayedline_new, StrCat(displayedline_old,StrGetCharAt(line,i)) );
i++;
SetTextOverlay(10,vspacing,400,font, colour,displayedline_new);
PlaySound(1);
Wait(5);
}
return textid;
}
The problem is that both StrCopy and StrCat expect a string as their parameter. Try replacing the line in quiestion with:
StrFormat(displayedline, "%s%c", displayedline, StrGetCharAt(line,i));
Great! That did the trick,
Now I am left with one small problem:
I want to check for spaces:
is the character at place "i" a space, then wait a bit longer to play the next sound
if ( (StrComp(StrGetCharAt(line,i)," ") !=0 ){
Wait(10);
}
else {
Wait(5);
}
P.S. Waht does %s%c mean? I may be abvle to solve the rest of the questions myself once I understand the principle...
You had one opening brace too many:
if (StrComp(StrGetCharAt(line, i), " ") == 0) Wait(10);
else Wait(5);
As for the placeholders, I can't explain it very well.
Look at this:
Display("%d %d %s %s %c %c ...", intPercentD1, intPercentD2, strPercentS1, strPercentS2, chrPercentC1, chrPercentC2, ...);
Do you get it?
Quoteif (Ã, Ã, Ã, (StrComp(StrGetCharAt(line,i)," ")Ã, !=0Ã, ){
Again, unfortunately, StrGetCharAt() returns a character but StrComp expects a string.
But since it's just a single character you can compare them with the "==" operator:
if (StrGetCharAt(line,i) == ' ') {
Notice, how I replaced " " (string) with ' ' (character)
QuoteWaht does %s%c mean?
They are special tokens you can use when making a formated string. Strazer already shown how %d works, I just try to explain what the StrFormat(displayedline, "%s%c", displayedline, StrGetCharAt(line,i)) line does:
Let's suppose:
displayedline = "" (is empty)
line ="abcde" (some string)
Since it's in a while loop we have:
1. iteration
StrFormat(
displayedline, "%s%c",
displayedline, StrGetCharAt(line,i))Ã, --- replaces %s with a content of the
displayedline = "" and %c with a content of the StrGetCharAt(line,i)='a', so "%s%c" becomes "a". Finally, that new string "a" is copied to
displayedline.
2. iteration
Actions are repeated, but by replacing "%s%c" with displayedline and StrGetCharAt(line,i) we get:
"ab" (because now displayedline = "a" and StrGetCharAt(line,i) = 'b')
3. iteration
"abc"
etc...
Why are there %s, %d, %c? Because each token represents a certain type, i.e.:
%s - string
%c - char
%d - decimal
displayedline is a
string and StrGetCharAt(line,i) returns a
char that's why there is "%s%c".
Also notice that it is sagnificant for the order of tokens to be identical to the order of parameters you out after "%s%d":
correct:StrFormat(displayedline, "
%s%c",
displayedline, StrGetCharAt(line,i))
wrong:StrFormat(displayedline, "%c
%s",
displayedline, StrGetCharAt(line,i))
correct:StrFormat(displayedline, "%c
%s", StrGetCharAt(line,i),
displayedline)
Thanks a lot! I learned a great deal from this.
Wonderfull!!!
Also, see AJA's agsCreditz plugin...
This (http://www.adventuregamestudio.co.uk/games.php?action=detail&id=192) hopefully links to the older version, as I heard the new one does not have the feature...
don't mean to sound dumb but isn't typewriter an option in th creditz plugin?
Thanks for all the help!
here is the final, wqorking and tested code.
Off course a sound1.wav is stored in the game root.
//#######################################
//=============================================
//TypeLine types a text on the screen, letter by letter, at a vspace distance from the
//top of the screen
//The function returns the id of the line printed, so this can be called in order to identify
//the line later on; e.g. in order to remove the line
//=============================================
function TypeLine(string line, int vspacing){
//declare local vars
int length=0;
int i = 0;
string displayedline;
int textid = 0;
//initialise vars , overdoing it a bit ;-)
length = 0;
i=0;
StrCopy(displayedline," ");
textid = CreateTextOverlay(xpos,50,400,font,colour,displayedline);
//get string length, to know how long the loop must run
length=StrLen(line); //set string length
//start loop
while(i<length){
// 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, 10,vspacing,400, font, colour, displayedline);
// if a space is added to the string do not play a sound, else play a 'tick'
if (StrGetCharAt(line,i) == ' '){
Wait(10);
}
else{
PlaySound(1);
Wait(5);
}
//increase the loop counter
i++;
}
return textid;
}
//#########################################
function room_a() {
// script for room: First time player enters screen
//type lines and play sound of ticking machine
line1 = TypeLine(" first line", 50);Wait(60);
line2 = TypeLine(" second line", 70);
Wait(60);
line3 = TypeLine(" 3rd line.", 90);
Wait(60);
Wait(100);
//after a pauzethe text is removed again
RemoveOverlay(line1);
RemoveOverlay(line2);
RemoveOverlay(line3);
Right.
Listen to Scorp. When in doubt, he's right. :)
It should be
if (StrGetCharAt(line, i) == ' ') Wait(10);
else Wait(5);
My version:
http://www.2dadventure.com/ags/type_TEST.zip source code
// room script file
int timer=0;
int count=0;
int line=0;
string output;
string text;
#sectionstart room_aÃ, // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {Ã, // script for room: Player enters screen (before fadein)
Ã, RawSaveScreen();
Ã, RawSetColor(2);
}
#sectionend room_aÃ, // DO NOT EDIT OR REMOVE THIS LINE
function typer(int y, int clear){
Ã, StrSetCharAt(output,StrLen(output),StrGetCharAt(text,count));
Ã, if (StrGetCharAt(text,count)!=' ') PlaySound(3);Ã, //type sound
Ã, RawPrint(5,y,output);
Ã, count++;
Ã, if (count>StrLen(output)){
Ã, Ã, line++;
Ã, Ã, StrFormat(output,"");
Ã, Ã, count=0;
Ã, Ã, if (clear==1){
Ã, Ã, Ã, PlaySound(2);Ã, //return sound
Ã, Ã, Ã, Wait(30);
Ã, Ã, Ã, RawRestoreScreen();
Ã, Ã, }
Ã, }
}
#sectionstart room_bÃ, // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {Ã, // script for room: Repeatedly execute
Ã, timer++;
Ã, ifÃ, Ã, Ã, (timer%5==0 && line==0){
Ã, Ã, StrFormat(text,"Somewhere in the galaxie a half broken space rig is");
Ã, Ã, typer(200,0);
Ã, }
Ã, else if (timer%5==0 && line==1){
Ã, Ã, StrFormat(text,"flying trough space.");
Ã, Ã, typer(210,1);
Ã, }
Ã, else if (timer%5==0 && line==2){
Ã, Ã, StrFormat(text,"On board is a happy triggered, bunny hopping, bad ass");
Ã, Ã, typer(200,0);
Ã, }
Ã, else if (timer%5==0 && line==3){
Ã, Ã, StrFormat(text,"space pirate called James T. Windmill.");
Ã, Ã, typer(210,1);
Ã, }
Ã, else if (timer%5==0 && line==4){
Ã, Ã, StrFormat(text,"He is in search of his mothership, Coell-Decka.");
Ã, Ã, typer(200,1);
Ã, }
Ã, else if (timer%5==0 && line==5){
Ã, Ã, StrFormat(text,"At this point the rig is about to fly trough an asteroid");
Ã, Ã, typer(200,0);
Ã, }
Ã, else if (timer%5==0 && line==6){
Ã, Ã, StrFormat(text,"field that the badly damaged rig can not survive.");
Ã, Ã, typer(210,1);
Ã, }
Ã, else if (timer%5==0 && line==7){
Ã, Ã, StrFormat(text,"James, however, is preoccupied with other things.");
Ã, Ã, typer(200,1);
Ã, }
}
#sectionend room_bÃ, // DO NOT EDIT OR REMOVE THIS LINE