help with a function..

Blitz3D Forums/Blitz3D Beginners Area/help with a function..

Angel(Posted 2003) [#1]
I'm having trouble getting this function to work in my program. What it's SUPPOSED to do is read all the lines in a text file, and place them on the screen, in a message window, 4 lines at a time. When you press a key, it goes to the next 4 lines, until there is no text left. I'm using a text file with 5 lines and it skips the first four, instead of waiting for you to press a key. I'm using Blitz Plus, but without ANY actual blitz plus commands, so it SHOULD act like its a blitz basic game. Here's the code:
Function MWin(file$)
Color tr,tg,tb

crap$="progs\"+file$+".txt"
file$=crap$
filein=ReadFile(file$)

num=0
While Not Eof(filein)
sline.someline=New someline
sline\aline$=ReadLine$(filein)
sline\index=num+1
Wend
CloseFile(filein)
placemwin=Int(reswidth/2)-160

.mwinagain
For sline.someline=Each someline
If sline\index=1 Then
	line1$=sline\aline$
EndIf
If sline\index=2 Then
	line2$=sline\aline$
EndIf
If sline\index=3 Then
	line3$=sline\aline$
EndIf
If sline\index=4 Then
	line4$=sline\aline$
EndIf
Delete sline
Next


RenderGraphics()

DrawImage mwin,placemwin,0
Text placemwin+5,5,line1$
Text placemwin+5,20,line2$
Text placemwin+5,35,line3$
Text placemwin+5,50,line4$

Flip

FlushKeys()
WaitKey()

linenum=0
For sline.someline=Each someline
linenum=linenum+1
sline\index=sline\index-4
Next

If linenum>0 Then Goto mwinagain

End Function

I know it's not the best or cleanest code, but I'm still new at this (hence the reason this is in the beginner's section lol).


Curtastic(Posted 2003) [#2]
although I suggest you dont use indexes at all, 'num' isnt going up in the While loop.


Angel(Posted 2003) [#3]
god i can't believe i'm so stupid! thanks, dude!!!


Curtastic(Posted 2003) [#4]
np,
you could do something like this though
Function MWin(file$)

local currentline.someline,aftercurrentline.someline

Color tr,tg,tb

crap$="progs\"+file$+".txt"
file$=crap$
filein=ReadFile(file$)


While Not Eof(filein)
sline.someline=New someline
sline\aline$=ReadLine$(filein)
Wend
CloseFile(filein)
placemwin=Int(reswidth/2)-160

.mwinagain

RenderGraphics()

DrawImage mwin,placemwin,0
currentline=first someline
for show=1 to 4
if currentline=null then exit
Text placemwin+5,5+15*show,currentline\aline$
aftercurrentline=after currentline
delete currentline
currentline=aftercurrentline
next


Flip

FlushKeys()
WaitKey()


If currentline<>null Then Goto mwinagain

End Function


edit: oops I forgot a line


Angel(Posted 2003) [#5]
I tried your method, Coorae, but it didn't work :(

here's the changes i made to my own (the While loop):
While Not Eof(filein)
num=num+1
sline.someline=New someline
sline\aline$=ReadLine$(filein)
sline\index=num
Wend


Now, it posts the first 4 lines on the screen, but when i press a button, it doesn't do anything (doesn't show the 5th line). I don't know if this is progress...

btw i took out the FlushKeys() line, i accidentally added that when i was trying different things with the code :)


Angel(Posted 2003) [#6]
Ok, finally solved the problem. Thanks for the help!