GAH!! MY BRAIN HURTS!

Blitz3D Forums/Blitz3D Beginners Area/GAH!! MY BRAIN HURTS!

it almost works! the code you gave does work, but I'm getting a mem access violation when i use it in-game. Here's my new functions (small revisions, mainly got rid of semicolons):

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 = 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 


What wrong with it?

I found that getting rid of:
	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

makes using the function do nothing.