Server Help

Bot Questions - How to save/read to/from an outside file?

LearJett+ - Wed Sep 14, 2005 7:52 pm
Post subject: How to save/read to/from an outside file?
I apologize in advance if anyone thinks this is a stupid question -

How do you get a Mervbot to save and read to and from an outside file? Like a .dat or .ini for example.

Any assistance is appreciated, thanks.
CypherJF - Wed Sep 14, 2005 8:17 pm
Post subject:
What bot core are you dealing with? Then determine whether or not it was writen in. Then look up the appropriate I/O functions for the language.
D1st0rt - Wed Sep 14, 2005 10:41 pm
Post subject:
He said merv. I Recommend using GetPrivateProfileString if you're running it on windoze as its the easiest
LearJett+ - Wed Sep 14, 2005 10:53 pm
Post subject:
I added the word Merv in after he posted, so that other people could post as well.

I used GetPrivateProfileString and got it to work (Some how icon_lol.gif) Thanks for the help.
Bak - Thu Sep 15, 2005 12:30 am
Post subject:
I recommend http://www.gamedev.net/reference/articles/article1127.asp
Maverick - Thu Sep 15, 2005 2:47 am
Post subject:
Better use the Mervbot tutorial which contains all these code snippets - copy/paste and you are already half way done.

http://wiki.minegoboom.com/index.php/MERVBot_Tutorial
http://bots.sscentral.com/mav/files/MERVbot%20tutorial.html (download friendly)
Cyan~Fire - Thu Sep 15, 2005 4:01 pm
Post subject:
If you want the INI-type format, use GetPrivateProfileString() as d1st suggested. If you want a customly-formatted file, use the iostream classes, or, even better, the C iostream library.
Quan Chi2 - Thu Sep 15, 2005 4:20 pm
Post subject:
hmmm I normally use text files.. I should start using ini files biggrin.gif
Maverick - Thu Sep 15, 2005 5:09 pm
Post subject:
Beware that text files (even .ini) always work slower when they become larger. I believe that .ini files in combination with GetPrivateProfileString() is even slower when they become somewhat larger.
Quan Chi2 - Thu Sep 15, 2005 6:15 pm
Post subject:
um.. or you can just code it so that the bot reads from memory right?
BDwinsAlt - Thu Sep 15, 2005 7:03 pm
Post subject:
Java....

Oh i mean Suuuurrrreeeee, lets go with that sa_tongue.gif
Bak - Thu Sep 15, 2005 7:48 pm
Post subject:
GetPrivateProfileString is a system call that will slow down your code if you were to do something dumb like call it many times in a loop
Cyan~Fire - Thu Sep 15, 2005 10:37 pm
Post subject:
It's really not all that slow. I know I'm usually an efficiency freak, but I say when a system call exists that'll do your code for you (and, in most cases, more safely) you mightn't as well use it.
Cerium - Thu Sep 15, 2005 11:27 pm
Post subject:
Does the file get opened/closed on each call to GetPrivateProfileString?
Maverick - Fri Sep 16, 2005 7:05 am
Post subject:
I believe it does, else there would be a system call to open/close the file.
The best solution to using GetPrivateProfileString , as Quan said, would be to load as much as you can into memory.
(Most people already do that via a loadSettings() method)

However, you need to save the data back to the .ini file once in a while (if the data is changed), giving the possibility to losing data when the bot gets shut down before its saved to the HD and making your bot suddenly slow when its saving to the HD.

So.. if you can, use a sql database instead sa_tongue.gif
Cyan~Fire - Fri Sep 16, 2005 3:59 pm
Post subject:
No, no, no. Don't use sql, that's retarded. Just load at the beginning, save at the end, and don't let your computer shut off uunnaturally. icon_razz.gif
Quan Chi2 - Fri Sep 16, 2005 5:02 pm
Post subject:
I dont know how to make a database yet, but wou;ouldn't saving profiles to an ini file make the bot slower and take alot of memory because the bot has to record each profile....? Imagine if you had a ton of traffic tongue.gif that would be alot of profiles lol..depending on what you're doing with GetPrivateProfileStrin() right? But mabye you can save profiles to multiple ini files? To make the load less for each file? I dunno
Cyan~Fire - Fri Sep 16, 2005 6:48 pm
Post subject:
Multiple files would just make it worse. The problem is opening/closing files repeatedly, not the size of the file itself. The size has only a negligible effect.
Quan Chi2 - Fri Sep 16, 2005 6:57 pm
Post subject:
whats causing the open and close speed?
Cyan~Fire - Fri Sep 16, 2005 11:27 pm
Post subject:
Figure it out, it's already been said.
Underlord - Sun Sep 18, 2005 8:53 pm
Post subject:
Sample Code to retrieve settings from a .ini file
Code: Show/Hide

#include "spawn.h"

const int BUFFER_LEN = 256;
static char buffer[BUFFER_LEN];
static char path[BUFFER_LEN];

void botInfo::LoadSettings()
{
   // load settings from settings.ini
   // initial_arena and max_deaths global variables
   GetCurrentDirectory(BUFFER_LEN - 64, path);
   strcat(path, "\\settings.ini");

   String s;

   GetPrivateProfileString("Bot", "ArenaName", "error", buffer, BUFFER_LEN, path);
   s = buffer;
   strcpy(initial_arena,s);

   GetPrivateProfileString("Bot", "MaxDeaths", "error", buffer, BUFFER_LEN, path);
   s = buffer;
   max_deaths = s.toInteger();
}


Then 'settings.ini' in the mervbot.exe folder has this format
Code: Show/Hide

// [Bot] is from first argument in GetPrivateProfileString
// ArenaName= is second

[Bot]
ArenaName=league

MaxDeaths=3

D1st0rt - Thu Sep 22, 2005 3:09 am
Post subject:
Dunno if this is improper procedure, but I find it easy to use the INI macros from TM MER:

Code: Show/Hide
//Load Functions, Courtesy of SOS
#define G(name) ZeroMemory(buffer, 192);\
      GetPrivateProfileString(title.msg, name, "-1", buffer, 192, Path)

#define G2(a) if (isNumeric(buffer))\
         a = getInteger(buffer, 10);\
      else\
         a = 0

#define G3(a) if (isNumeric(buffer))\
         a = getLong(buffer, 10);\
      else\
         a = 0

void botInfo::load()
{
   char Path[520];
   GetCurrentDirectory(520, Path);
   strcat(Path, "\\lvztoggle.ini");

   char buffer[192];
   String title = "Objects";

   G("TimeInterval");
   G2(interval);

   ...   
}

Cyan~Fire - Thu Sep 22, 2005 4:02 pm
Post subject:
I prefer GetPrivateProfileInt() to those G2 and G3 macros, but whatever. Zeroing the memory ahead of time is also useless since GPPS null-terminates the string anyway.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group