function WriteLine(linenumber,line,character,face){
	if(currentline==linenumber){
	let name=line;
	line=line~":@";
	line=line~character;
		if(wait==0){
			if(name=="Kurumi"){ textcolor=[180,240,60]; SEtext=("\script\SoundEffects\text2.wav"); }
			if(name=="Hotaru"){ textcolor=[255,160,20]; SEtext=("\script\SoundEffects\text3.wav"); }
			if(name=="Tomoko"){ textcolor=[170,65,140]; SEtext=("\script\SoundEffects\text3.wav"); }
			if(name=="Setsuko"){ textcolor=[210,160,50]; SEtext=("\script\SoundEffects\text3.wav"); }
			if(name=="Ayano"){ textcolor=[150,30,0]; SEtext=("\script\SoundEffects\text4.wav"); }
			if(name=="Midori"){ textcolor=[130,130,130]; SEtext=("\script\SoundEffects\text3.wav"); }
			if(name=="Tomomi"){ textcolor=[135,205,235]; SEtext=("\script\SoundEffects\text4.wav"); }
			if(name=="Youko"){ textcolor=[240,160,175]; SEtext=("\script\SoundEffects\text1.wav"); }
			if(name=="Amaya"){ textcolor=[255,255,255]; SEtext=("\script\SoundEffects\text3.wav"); }
			if(name=="Sayuri"){ textcolor=[240,120,0]; SEtext=("\script\SoundEffects\text2.wav"); }
			if(name=="Mai"){ textcolor=[205,170,125]; SEtext=("\script\SoundEffects\text4.wav"); }
			if(name=="Haruna"){ textcolor=[240,65,0]; SEtext=("\script\SoundEffects\text1.wav"); }
			if(name=="Takeo"){ textcolor=[60,95,205]; SEtext=("\script\SoundEffects\text3.wav"); }
			if(name=="Masahiro"){ textcolor=[205,55,0]; SEtext=("\script\SoundEffects\text2.wav"); }
			if(name=="Ryo"){ textcolor=[205,205,0]; SEtext=("\script\SoundEffects\text2.wav"); }
			if(name=="Shinichi"){ textcolor=[170,170,170]; SEtext=("\script\SoundEffects\text1.wav"); }
			if(name=="Nanami"){ textcolor=[255,170,220]; SEtext=("\script\SoundEffects\text4.wav"); }
			if(name=="Voice"){ textcolor=[130,130,130]; SEtext=("\script\SoundEffects\text3.wav"); }
			if(name=="Witches"){ textcolor=[130,130,130]; SEtext=("\script\SoundEffects\text3.wav"); }

			if(name=="Masahiro"){ speakingside=1; ObjEffect_SetTexture(OBJleft,face); }
			else{ speakingside=2; ObjEffect_SetTexture(OBJright,face); }
			
			if(linenumber==1 && speakingside==1){ oldside=2; characterscroll=18; }
			if(linenumber==1 && speakingside==2){ oldside=1; characterscroll=0; }
			
			if(speakingside<oldside){
				if(linenumber>1){ movecharacter=1; }		
				ObjEffect_SetVertexColor(OBJleft,0,255,255,255,255); ObjEffect_SetVertexColor(OBJleft,1,255,255,255,255);
				ObjEffect_SetVertexColor(OBJleft,2,255,255,255,255); ObjEffect_SetVertexColor(OBJleft,3,255,255,255,255);
				ObjEffect_SetVertexColor(OBJright,0,255,100,100,100); ObjEffect_SetVertexColor(OBJright,1,255,100,100,100);
				ObjEffect_SetVertexColor(OBJright,2,255,100,100,100); ObjEffect_SetVertexColor(OBJright,3,255,100,100,100);
			}
			if(speakingside>oldside){
				if(linenumber>1){ movecharacter=2; }
				ObjEffect_SetVertexColor(OBJleft,0,255,100,100,100); ObjEffect_SetVertexColor(OBJleft,1,255,100,100,100);
				ObjEffect_SetVertexColor(OBJleft,2,255,100,100,100); ObjEffect_SetVertexColor(OBJleft,3,255,100,100,100);
				ObjEffect_SetVertexColor(OBJright,0,255,255,255,255); ObjEffect_SetVertexColor(OBJright,1,255,255,255,255);
				ObjEffect_SetVertexColor(OBJright,2,255,255,255,255); ObjEffect_SetVertexColor(OBJright,3,255,255,255,255);
			}

			if(name=="Masahiro"){ oldside=1; }
			else{ oldside=2; }
		
		} //wait==0
		
		if(i<(length(line)) && shortbreak==0){
			let letterwidth=[0,0,0];
			if(line[i]=='a'){ letterwidth=[1,11,8]; } if(line[i]=='A'){ letterwidth=[288,302,12]; }
			if(line[i]=='b'){ letterwidth=[12,24,10]; } if(line[i]=='B'){ letterwidth=[303,313,9]; }
			if(line[i]=='c'){ letterwidth=[24,34,9]; } if(line[i]=='C'){ letterwidth=[314,328,12]; }
			if(line[i]=='d'){ letterwidth=[35,45,10]; } if(line[i]=='D'){ letterwidth=[328,342,12]; }
			if(line[i]=='e'){ letterwidth=[47,59,9]; } if(line[i]=='E'){ letterwidth=[342,354,10]; }
			if(line[i]=='f'){ letterwidth=[59,67,5]; } if(line[i]=='F'){ letterwidth=[354,364,9]; }	
			if(line[i]=='g'){ letterwidth=[67,77,9]; } if(line[i]=='G'){ letterwidth=[365,379,13]; }
			if(line[i]=='h'){ letterwidth=[79,91,9]; } if(line[i]=='H'){ letterwidth=[380,392,11]; }
			if(line[i]=='i'){ letterwidth=[91,97,4]; } if(line[i]=='I'){ letterwidth=[393,399,5]; }	
			if(line[i]=='j'){ letterwidth=[98,104,5]; } if(line[i]=='J'){ letterwidth=[400,408,6]; }
			if(line[i]=='k'){ letterwidth=[105,117,9]; } if(line[i]=='K'){ letterwidth=[408,420,10]; }
			if(line[i]=='l'){ letterwidth=[117,123,4]; } if(line[i]=='L'){ letterwidth=[420,430,9]; }
			if(line[i]=='m'){ letterwidth=[124,140,14]; } if(line[i]=='M'){ letterwidth=[431,447,14]; }
			if(line[i]=='n'){ letterwidth=[141,153,9]; } if(line[i]=='N'){ letterwidth=[447,459,11]; }
			if(line[i]=='o'){ letterwidth=[153,165,10]; } if(line[i]=='O'){ letterwidth=[460,474,13]; }
			if(line[i]=='p'){ letterwidth=[165,177,10]; } if(line[i]=='P'){ letterwidth=[475,485,9]; }
			if(line[i]=='q'){ letterwidth=[177,189,10]; } if(line[i]=='Q'){ letterwidth=[486,500,13]; }
			if(line[i]=='r'){ letterwidth=[189,197,6]; } if(line[i]=='R'){ letterwidth=[501,513,11]; }
			if(line[i]=='s'){ letterwidth=[198,208,8]; } if(line[i]=='S'){ letterwidth=[514,524,9]; }
			if(line[i]=='t'){ letterwidth=[208,214,5]; } if(line[i]=='T'){ letterwidth=[525,537,11]; }
			if(line[i]=='u'){ letterwidth=[215,227,9]; } if(line[i]=='U'){ letterwidth=[538,550,11]; }
			if(line[i]=='v'){ letterwidth=[227,239,9]; } if(line[i]=='V'){ letterwidth=[551,565,13]; }
			if(line[i]=='w'){ letterwidth=[239,253,12]; } if(line[i]=='W'){ letterwidth=[566,584,16]; }
			if(line[i]=='x'){ letterwidth=[254,266,10]; } if(line[i]=='X'){ letterwidth=[585,597,11]; }
			if(line[i]=='y'){ letterwidth=[266,278,9]; } if(line[i]=='Y'){ letterwidth=[598,612,12]; }
			if(line[i]=='z'){ letterwidth=[278,288,8]; } if(line[i]=='Z'){ letterwidth=[613,623,9]; }

			if(line[i]=='1'){ letterwidth=[624,630,5]; } if(line[i]=='2'){ letterwidth=[631,641,9]; }
			if(line[i]=='3'){ letterwidth=[642,652,9]; } if(line[i]=='4'){ letterwidth=[653,663,9]; }
			if(line[i]=='5'){ letterwidth=[664,674,9]; } if(line[i]=='6'){ letterwidth=[675,685,9]; }
			if(line[i]=='7'){ letterwidth=[686,696,9]; } if(line[i]=='8'){ letterwidth=[697,707,9]; }
			if(line[i]=='9'){ letterwidth=[708,718,9]; } if(line[i]=='0'){ letterwidth=[719,729,9]; }
			
			if(line[i]=='?'){ letterwidth=[730,740,9]; } if(line[i]=='!'){ letterwidth=[741,745,3]; } // ? !
			if(line[i]=='.'){ letterwidth=[746,750,3]; } if(line[i]==','){ letterwidth=[751,755,3]; } // . ,
			if(line[i]==':'){ letterwidth=[756,760,3]; } if(line[i]=='`'){ letterwidth=[761,765,3]; } // : '
			if(line[i]=='['){ letterwidth=[766,774,6]; } if(line[i]==']'){ letterwidth=[766,774,6]; } // " x2
			if(line[i]=='('){ letterwidth=[848,856,6]; } if(line[i]==')'){ letterwidth=[856,864,6]; } // ( )
			if(line[i]=='<'){ letterwidth=[864,876,11]; } if(line[i]=='>'){ letterwidth=[877,889,11]; } // < >
			if(line[i]=='*'){ letterwidth=[837,847,9]; } if(line[i]=='&'){ letterwidth=[823,837,12]; } // * &
			if(line[i]=='-'){ letterwidth=[890,898,7]; } // -

			if(line[i]=='+'){ letterwidth=[0,0,5]; newword=1; wordsize=500; shortbreak=20; } // Enter
			if(line[i]=='@'){ letterwidth=[0,0,5]; newword=1; wordsize=500; } // Enter without a break
			if(line[i]==' '){ letterwidth=[0,0,5]; newword=1; } // Space
			if(line[i]=='%'){ shortbreak=10; }
			if(line[i]=='#'){
			newcolor[3]=textcolor[0]; newcolor[4]=textcolor[1]; newcolor[5]=textcolor[2];
			textcolor[0]=newcolor[0]; textcolor[1]=newcolor[1]; textcolor[2]=newcolor[2];
			newcolor=[newcolor[3],newcolor[4],newcolor[5],textcolor[0],textcolor[1],textcolor[2]];
			}

			let xsize=letterwidth[1]-letterwidth[0];
			let ysize=20;
			let scale=1;
			letter=(Obj_Create(OBJ_EFFECT));
			if(wordsize>260 && newword==1){ wordsize=-5; lineypos+=18; newword=1; }
			Obj_SetPosition(letter,52+wordsize,366+lineypos); ObjEffect_SetScale(letter,0,0);
			ObjEffect_SetLayer(letter,7); ObjEffect_SetTexture(letter,GRtext); ObjEffect_SetRenderState(letter,ALPHA);
			ObjEffect_SetPrimitiveType(letter,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(letter,4);
			ObjEffect_SetVertexXY(letter,0,0,-(ysize/2)); ObjEffect_SetVertexUV(letter,0,letterwidth[0],0);
			ObjEffect_SetVertexXY(letter,1,xsize,-(ysize/2)); ObjEffect_SetVertexUV(letter,1,letterwidth[1],0);
			ObjEffect_SetVertexXY(letter,2,0,ysize/2); ObjEffect_SetVertexUV(letter,2,letterwidth[0],ysize);
			ObjEffect_SetVertexXY(letter,3,xsize,ysize/2); ObjEffect_SetVertexUV(letter,3,letterwidth[1],ysize);
			ObjEffect_SetVertexColor(letter,0,255,textcolor[0],textcolor[1],textcolor[2]); ObjEffect_SetVertexColor(letter,1,255,textcolor[0],textcolor[1],textcolor[2]);
			ObjEffect_SetVertexColor(letter,2,255,textcolor[0],textcolor[1],textcolor[2]); ObjEffect_SetVertexColor(letter,3,255,textcolor[0],textcolor[1],textcolor[2]);
			letters=letters~[letter];
			letterscale=letterscale~[letter];
			letterscale[length(letters)-1]=2;
			letterfade=letterfade~[letter];
			letterfade[length(letters)-1]=0;
			letterred=letterred~[letter];
			letterred[length(letters)-1]=textcolor[0];
			lettergreen=lettergreen~[letter];
			lettergreen[length(letters)-1]=textcolor[1];
			letterblue=letterblue~[letter];
			letterblue[length(letters)-1]=textcolor[2];
			wordsize+=letterwidth[2];
			newword=0;
			i++;
			wait=0;
			if(busywriting==0 && shortbreak==0){ PlaySE(SEtext); busywriting=5; }
		} // draw text	
	} // currentline
} // function

if(shortbreak>0){ shortbreak--; }
if(busywriting>0){ busywriting--; }
if(i>=(length(line))){ wait++; }

Obj_SetPosition(OBJleft,cx-100+(characterscroll/3),cy+100-characterscroll);
Obj_SetPosition(OBJright,cx+100+(characterscroll/3),cy+82+characterscroll);

if(movecharacter==1){ if(characterscroll<18){ characterscroll+=3; } }
if(movecharacter==2){ if(characterscroll>0){ characterscroll-=3; } }

if(nameappear>0){
	SetCommonData("NamePresent",nameappear);
	CreateEnemyFromFile("script\Functions\names.txt",0,0,0,0,nameappear);
	nameappear=0;
}
	
let j=0;
while(j<length(letters)){
	if(Obj_BeDeleted(letters[j])){
	letters=erase(letters,j); letterfade=erase(letterfade,j); letterscale=erase(letterscale,j);
	letterred=erase(letterred,j); lettergreen=erase(lettergreen,j); letterblue=erase(letterblue,j);
	j--;
	}
	else{
	if(letterscale[j]>1){ letterscale[j]=letterscale[j]-0.1; }
	if(letterfade[j]<255){ letterfade[j]=letterfade[j]+255/10; }
	ObjEffect_SetScale(letters[j],1,letterscale[j]);
	ObjEffect_SetVertexColor(letters[j],0,letterfade[j],letterred[j],lettergreen[j],letterblue[j]); ObjEffect_SetVertexColor(letters[j],1,letterfade[j],letterred[j],lettergreen[j],letterblue[j]);
	ObjEffect_SetVertexColor(letters[j],2,letterfade[j],letterred[j],lettergreen[j],letterblue[j]); ObjEffect_SetVertexColor(letters[j],3,letterfade[j],letterred[j],lettergreen[j],letterblue[j]);

	if((GetKeyState(VK_SHOT)==KEY_PUSH && enableZ==true) || wait==waittime){ Obj_Delete(letters[j]); nextline=1; }
	if((GetKeyState(VK_SKIP)==KEY_PUSH && enableskip==true)){ Obj_Delete(letters[j]); nextline=2; skipped=linenumber; }
	}
j++;
}