GAH!! MY BRAIN HURTS!

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

grrr....I'm having all sorts of problems with this, could you help me out?

this is the creator :
AppTitle "SW:WRH Conversation creator"
Global filename$=""
Global launcher$=""
Global funcname$=""

Global quit=0
Global check$=""

Type TQuestion
Field question$
Field ans1$
Field ans2$
Field ans3$
Field fol1$
Field fol2$
Field fol3$
End Type 

Graphics 1280,1024,32,2






;createconversation
;create the conversation
Text 1, 1, "WELCOME TO THE SW:WRH CONVERSATION CREATOR.  If you quit (click the X) It WILL NOT SAVE. HIT ANY KEY TO CONTINUE"
WaitKey()
Cls 

filename$=Input$("What should the filename of this conversation be (if the file already exhists, put its name here too, extensions are unnecesary)? ") + ".txt"
check(filename$)
If quit=1 Then Goto quitlabel


funcname$=Input$("What would you like the Function name For this conversation To be?   ")
check(funcname$)
If quit=1 Then Goto quitlabel

Global initquestion$ = Input$("What should the First thing the NPC says be? ")

GetQuestion$(initquestion$)


writetofile 


Cls 


.quitlabel
End 

Function check(check$)
If check$="quit" Then quit=1
;Goto quitlabel
;EndIf 
End Function 

Function writetofile()


test = FileType(filename$)

;if it doesn't
If Not test Then
		
	;createfile
	file = WriteFile(filename$)


;if it does		
Else
	
	;open file
	file = OpenFile(filename$)
	;seek to end of file
	SeekFile file, FileSize(filename$)
	
End If
;======================================================TO BE CHANGED================================
;WriteLine file, "Type TQuestion"
;WriteLine file, "Field question$"
;WriteLine file, "Field ans1$"
;WriteLine file, "Field ans2$"
;WriteLine file, "Field ans3$"
;WriteLine file, "Field fol1$"
;WriteLine file, "Field fol2$"
;WriteLine file, "Field fol3$"
;WriteLine file, "End Type"



;For question1.TQuestion = Each TQuestion
;WriteLine file, "question1.TQuestion = New TQuestion"
;WriteLine file, "question1\question$ = " + Chr(34) + question1\question$ + Chr(34) 
;WriteLine file, "question1\ans1$ = " + Chr(34) + question1\ans1$ + Chr(34)
;WriteLine file, "question1\ans2$ = " + Chr(34) + question1\ans2$ + Chr(34) 
;WriteLine file, "question1\ans3$ = " + Chr(34) + question1\ans3$ + Chr(34)

;If question1\fol1$ <> "" Then WriteLine file, "question1\fol1$ = " + Chr(34) + question1\fol1$ + Chr(34)

;If question1\fol2$ <> "" Then WriteLine file, "question1\fol2$ = " + Chr(34) + question1\fol2$ + Chr(34)

;If question1\fol3$ <> "" Then WriteLine file, "question1\fol3$ = " + Chr(34) + question1\fol3$ + Chr(34)

;Next 

For question1.TQuestion = Each TQuestion

WriteLine file, question1\question$
WriteLine file, question1\ans1$
WriteLine file, question1\ans2$
WriteLine file, question1\ans3$
WriteLine file, question1\fol1$
WriteLine file, question1\fol2$
WriteLine file, question1\fol3$

Next 





;======================================================TO BE CHANGED================================


CloseFile file



End Function 

Function GetQuestion$(q$)

	Print 
	Print "-----------------"
	Print 

	Print "Please enter answers that can be given for"
	Print "this question: " + q$
	a1$ = Input (" answer1=")	
	follow1$ = Input$("  followed by=")

	
	a2$ = Input (" answer2=")
	follow2$ = Input$("  followed by=")

	a3$ = Input (" answer3=")
	follow3$ = Input$("  followed by=")
	
	question1.TQuestion = New TQuestion
	question1\question$ = q$
	question1\ans1$ = a1$
	question1\ans2$ = a2$
	question1\ans3$ = a3$
	question1\fol1$ = follow1$
	question1\fol2$ = follow2$
	question1\fol3$ = follow3$
	
	
	
		
	If follow1$ <> "" Then GetQuestion$(follow1$)	
	If follow2$ <> "" Then GetQuestion$(follow2$)	
	If follow3$ <> "" Then GetQuestion$(follow3$)	

End Function	


and this is the conversation function (need a TON of work here):
Function conversation(filename$, questiontoask$)

file = ReadFile(filename$)
Delete Each TQuestion
While Not (Eof(file))
	q.TQuestion = New TQuestion
	question1\question$ = ReadLine(file)
	question1\ans1$ = ReadLine(file)
	question1\ans2$ = ReadLine(file)
	question1\ans3$ = ReadLine(file)
	question1\fol1$ = ReadLine(file)
	question1\fol2$ = ReadLine(file)
	question1\fol3$ = ReadLine(file)
Wend 
CloseFile file

;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 q = Null Then Return ;--> the question was not found

gfxmouse = LoadImage("mouse01.bmp")
MaskImage gfxmouse, 255, 255, 255

bgimage = CreateImage(displaywidth, displayheight)
CopyRect 0, 0, displaywidth, displayheight, 0, 0, BackBuffer(), ImageBuffer(bgimage)

Repeat

Repeat 


Cls 
DrawImage bgimage, 0, 0
;UpdateWorld
;RenderWorld


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$
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$
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$
EndIf
;====================================

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()
Until Not followup$ <> ""
Flip()

Until KeyHit(1)

End Function 


and in the main program, the code :
Type TQuestion
Field question$
Field ans1$
Field ans2$
Field ans3$
Field fol1$
Field fol2$
Field fol3$
End Type 


and being called like so:
If KeyHit( 43 ) Then 

conversation("text.txt", "Hi")
 
EndIf 


finally, the text file generated by the creator is as follows:
Hi
Hi
Bye
I hate you
Bye


Bye
What?
OK.
Bye!
That's right!


That's right!
Ok
Bye
KK





Any help?