Valhalla Legends Forums Archive | Battle.net Bot Development | Miscellaneous Questions?

AuthorMessageTime
BaDDBLooD
[Edit - Ask the non-botdev-related questions somewhere else. Also, please use the [ code ] tag when posting code samples.]

And, is there a Easer way to do this code:

[code]Private Function GetQuote() As String
Dim sQuote As String
Dim QuoteFilename As String
Dim QuoteFilenumber As Integer
Dim QuoteList(1 To 100) As String
Dim QuoteCounter As Integer
Dim QuoteNumber As Integer
QuoteCounter = 1
On Error GoTo errhandler:

QuoteFilename = "Quotes.txt"
QuoteFilenumber = FreeFile

Open QuoteFilename For Input As QuoteFilenumber

Do Until EOF(QuoteFilenumber)
Input #QuoteFilenumber, QuoteList(QuoteCounter)
QuoteCounter = QuoteCounter + 1
Loop

Close #QuoteFilenumber

Randomize
QuoteNumber = Int(((QuoteCounter - 1) * Rnd) + 1)

GetQuote = QuoteList(QuoteNumber)


Exit Function

errhandler:

'AddChat "ERROR: Quotes File does not exist" & vbRed & vbNewLine

End Function
[/code]
September 7, 2003, 1:54 AM
Grok
Yes, much easier.

Since you're storing each quote on a single line, try reading the whole file into a string with one call. Then call the VB Split() function on vbCrLf. Save the result into your array. Do all that in a stand-alone function so you only have to call it once during the lifetime of the program. Let's call that ReadQuotesFile().

Write a corresponding WriteQuoteFile() function that does a VB Join function to put the quotes array back into a string variable. Using a single call to write the string back to a disk file.

Now, write yourself a GetQuoteRand() function that reads a random quote and returns it to the caller.

Write an AddQuote() function that increases the quotes array size and appends the new quote passed as a parameter.

Now that you have a few functions that have a common purpose, put them all in a class file, so you can use them in lots of different programs.

HTH, Grok.
September 7, 2003, 2:30 AM
Camel
[devils advocate]
What if the user wants to modify the quotes file while the bot is running, or run multiple instances of the bot from the same directory?

Perhaps dynamicly reading the file isn't such a bad idea, as long as the memory is cleaned up properly.
[/devils advocate]
September 7, 2003, 7:07 AM
Adron
[devils advocate #2]
What if the user has 5 GB of quotes in that file? Wouldn't it be a good idea not to read the whole file?
[/devils advocate #2]
September 7, 2003, 11:06 AM
Kp
[quote author=Camel link=board=17;threadid=2605;start=0#msg20448 date=1062918478]
[devils advocate]What if the user wants to modify the quotes file while the bot is running, or run multiple instances of the bot from the same directory?
Perhaps dynamicly reading the file isn't such a bad idea, as long as the memory is cleaned up properly.[/devils advocate][/quote]Both of these can be handled pretty cleanly with just a few minor extensions to Grok's design. First, the quote filename can be user-specified -- thus you can run an arbitrary number of bots with different quote files. Second, either have a command from the user that reloads the quotes file, or periodically perform a stat(2) call on the file to determine if its information has changed. If the metadata is different, the file has been edited/replaced and should be reloaded. Otherwise it's the same one you already have, so don't waste time reloading it.
September 7, 2003, 4:31 PM
UserLoser
Hmm, your personal text looks familiar - "==:)^^(:==", I believe I own that account on USWest, or something similar.. could be East, I have too many 'illegals' to keep remember what I have and what I don't have.

Edit: No longer own the account, I guess the kid has the CDKey used to create it
September 7, 2003, 4:39 PM
Grok
As I have always said, it's much easier to tear down someone else's work than it is to create something yourself.

If you don't like a solution proposed by someone, create one yourself. I'm here trying to help the guy and you "devil's advocates" are trying to act all superior by trying to find a flaw in the solution. That doesn't help the guy, it confuses him. 5gb of quotes? Give it a rest. The guy is just starting out and doesn't need a more advanced solution, he just needs suggestions for a slightly improved design.

So either put up your ultimate no-fault quote delivery system that takes into consideration every possible requirement someone could ever have of it (including all those requirements not written in the guy's original post), or be considerate.
September 7, 2003, 7:44 PM
Adron
[quote author=Grok link=board=17;threadid=2605;start=0#msg20522 date=1062963866]
5gb of quotes? [/quote]

Possibly he won't have 5 gb of quotes, but even less quotes could well be too many to make sense to read into memory. I ran into that doing the wordgame bot - worked great and quick with an easy solution when i had a dictionary of 20 words, but when I tried it with a several megabyte dictionary, I had to index the file. Well, at first I tried just picking a random spot in the file, but then a long word would have a greater probability of being chosen (actually, a word following a long word), and that didn't work very well for short files...
September 8, 2003, 3:41 AM

Search