News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Having a little trouble with my NPC code

Started by Bustaballs, May 13, 2008, 06:45:39 PM

Previous topic - Next topic

Bustaballs

So, I'm just testing out some things again, only to find myself failing miserably at the most basic stuff. What this code is intended to do is read lines from a text file. Print them all in a row until there is a empty line and wait for a key to be pressed. It will continue to print the next lines in the same way. If there are two empty lines then the program will end. However, this code on works for the FIRST set of lines and just ends the program after that and I can't figure out why.

I'm trying to think up a good NPC chat system for my game that will read commands and text script from external files.

; PROJECT : Project1
; AUTHOR  : Nicholas
; CREATED : 5/13/2008
; EDITED  : 5/13/2008
; ---------------------------------------------------------------------

Filename$="NPC.TXT"

Dim TextLines$(100)
ReadFile Filename$,1
LineCount=0
Repeat
Inc LineCount
Textlines$(LineCount)= ReadString$(1)
Until EndOfFile(1)=true
CloseFile 1

LineCount=0

Do
Repeat
Inc LineCount
Print Textlines$(LineCount)
Until TextLines$(LineCount)=""
Sync
Waitkey
CLS RGB(0,0,0)
Check=LineCount+1

If TextLines$(Check)=""
End
Endif
Loop
QuoteOh please

kevin


Can you post the txt file you're loading also

Bustaballs

QuoteOh please

kevin


It works, it's running too fast though.  When user presses a key, the next loop will have drawn and the end will be detected.  So the user won't see the second page.


Filename$="NPC.TXT"

Dim TextLines$(100)
ReadFile Filename$,1
LineCount=0
Repeat
Inc LineCount
Textlines$(LineCount)= ReadString$(1)
Until EndOfFile(1)=true
CloseFile 1

LineCount=0

Do
Repeat
Inc LineCount
Print Textlines$(LineCount)
Until TextLines$(LineCount)=""
Sync
Waitkey
WaitnoKey
CLS RGB(0,0,0)
Check=LineCount+1

If TextLines$(Check)=""
End
Endif
Loop


Bustaballs

If TextLines$(Check)=""
                WaitKey
End
Endif


When I add waitkey before end, it doesn't stop the program from ending. Is there a simple work around for this that I can't think of?
QuoteOh please

kevin

 correct, that won't work.

hence the WaitNoKey in the sample I posted



Print "Hello"
Sync

; when the users presses a key here
Waitkey
; the program will fall through and run this command next.
; if the a key is still down, and it will be since the computer is much faster
; than a person.. then this command won't stop it either
Waitkey


This is why your program behaves the way it does.  It's not broken, the program logic doesn't take into account that when the computer reaches a WaitKey statement, that a key may still be down.


Bustaballs

#6
Ah, I see now.

You're the best, Kevin. Thanks.



Edit: Wait.

The code works assuming there's only two sets of text. It goes from first to last and skips anything in between. I don't understand why.
QuoteOh please

kevin


Bustaballs

QuoteChad: It's about time!
I thought you'd never show up.

Well, let's get started.
I'm tired of waiting.

Are you coming?
I'm not waiting all day.

This only prints:

QuoteChad: It's about time!
I thought you'd never show up.

Are you coming?
I'm not waiting all day.

It's really working for you no matter how long the text file is?
QuoteOh please

kevin


QuoteIt's really working for you no matter how long the text file is?

  Yes.  The version I posted works correctly.  I've already explained why.

Bustaballs

I see.

Well, thanks again. You're always a big help. This knocks out one small little piece of my project.
QuoteOh please