I looked at the code. Actually there wasn't much wrong. In the first loop, the Type that is filled in has another name than the Type that is created.
Other than that, I moved the file-reading to the beginning of the function, and added 'Delete Each TQuestion' for every 'Return' call.
Also I changed the loops to Repeat-Forever, and put the conditions (such as KeyHit(1)) that exit the loop in If statements.
In order to get it to work, at the end of the loop, I added questiontoask$ = followup$, so that the Function could search for the next question:
Other than that, I moved the file-reading to the beginning of the function, and added 'Delete Each TQuestion' for every 'Return' call.
Also I changed the loops to Repeat-Forever, and put the conditions (such as KeyHit(1)) that exit the loop in If statements.
In order to get it to work, at the end of the loop, I added questiontoask$ = followup$, so that the Function could search for the next question:
Graphics 1024,768,0,2 Const displaywidth = 800 Const displayheight = 600 Type TQuestion Field question$ Field ans1$ Field ans2$ Field ans3$ Field fol1$ Field fol2$ Field fol3$ End Type conversation("text.txt", "Hi") End ;===================================================================================================== ;===================================================================================================== ;===================================================================================================== Function conversation(filename$, questiontoask$) ;read file data file = ReadFile(filename$) Delete Each TQuestion While Not (Eof(file)) q.TQuestion = New TQuestion q\question$ = ReadLine(file) q\ans1$ = ReadLine(file) q\ans2$ = ReadLine(file) q\ans3$ = ReadLine(file) q\fol1$ = ReadLine(file) q\fol2$ = ReadLine(file) q\fol3$ = ReadLine(file) Wend CloseFile file ;create/load mouse image gfxmouse = CreateImage(8,8);LoadImage("mouse01.bmp") MaskImage gfxmouse, 255, 255, 255 ;copy screen to 'bgimage' bgimage = CreateImage(displaywidth, displayheight) CopyRect 0, 0, displaywidth, displayheight, 0, 0, BackBuffer(), ImageBuffer(bgimage) ;reset followup$ followup$ = "" ;main loop Repeat ;----SEARCH QUESTION THAT MATCHES 'questiontoask$'---- ;reset 'q' to empty before searching q.TQuestion = Null ;scan all TQuestions For temp.TQuestion = Each TQuestion ;if temp's question is the question to ask, then select temp and leave loop If temp\question$ = questiontoask$ Then q = temp: Exit Next ;if no matching question was found, leave function If q = Null Then Delete Each TQuestion: Return ;--> the question was not found ;----USER INPUT LOOP---- ;select loop Repeat ;draw 'bgimage' Cls DrawImage bgimage, 0, 0 ;UpdateWorld ;RenderWorld ;draw mouse DrawImage gfxmouse, MouseX(), MouseY() If (MouseY() < ((displayheight/4)*3)+((displayheight/4)*.3) + 12) And MouseY() > ((displayheight/4)*3)+((displayheight/4)*.3) Then Color 50, 50, 245 Rect 0, ((displayheight/4)*3)+((displayheight/4)*.3), displaywidth, 12, 1 Color 255, 255, 255 EndIf Color 0,0,0 Rect 0,0,displaywidth,displayheight/4,1 Color 0,0,0 Rect 0,(displayheight/4)*3,displaywidth,displayheight/4,1 Color 255, 255, 255 ;HIGHLIGHTS======================== If (MouseY() < ((displayheight/4)*3)+((displayheight/4)*.3) + 12) And MouseY() > ((displayheight/4)*3)+((displayheight/4)*.3) Then Color 50, 50, 245 Rect 0, ((displayheight/4)*3)+((displayheight/4)*.3), displaywidth, 12, 1 Color 255, 255, 255 If MouseHit(1) Then followup$ = q\fol1$: Exit EndIf If (MouseY() < ((displayheight/4)*3)+((displayheight/4)*.3) + 12 +50) And MouseY() > ((displayheight/4)*3)+((displayheight/4)*.3)+50 Then Color 50, 50, 245 Rect 0, ((displayheight/4)*3)+((displayheight/4)*.3)+50, displaywidth, 12, 1 Color 255, 255, 255 If MouseHit(1) Then followup$ = q\fol2$: Exit ;<----- added 'Exit' EndIf If (MouseY() < ((displayheight/4)*3)+((displayheight/4)*.3)+12+100) And MouseY() > ((displayheight/4)*3)+((displayheight/4)*.3)+100 Then Color 50, 50, 245 Rect 0, ((displayheight/4)*3)+((displayheight/4)*.3)+100, displaywidth, 12, 1 Color 255, 255, 255 If MouseHit(1) Then followup$ = q\fol3$: Exit EndIf ;==================================== ;draw optional answers Text 10,10, "" + followup$ Text 250,((displayheight/4)*3)+((displayheight/4)*.3), "" + q\ans1$ Text 250,((displayheight/4)*3)+((displayheight/4)*.3)+50, "" + q\ans2$ Text 250,((displayheight/4)*3)+((displayheight/4)*.3)+100, "" + q\ans3$ Flip() ;Esc=leave function If KeyHit(1) Then Return Forever ;<------- changed to 'Forever' If followup$ = "" Then Delete Each TQuestion: Return ;<-----added 'Delete Each TQuestion' questiontoask$ = followup$ Forever ;<------- changed to 'Forever' End Function