Author |
Message |
LearJett+ Server Help Squatter
Joined: Jul 11 2005 Posts: 281 Offline
|
Posted: 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. _________________

Last edited by LearJett+ on Wed Sep 14, 2005 8:26 pm, edited 1 time in total |
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: 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. _________________ Performance is often the art of cheating carefully. - James Gosling |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: 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 _________________
 |
|
Back to top |
|
 |
LearJett+ Server Help Squatter
Joined: Jul 11 2005 Posts: 281 Offline
|
Posted: 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 ) Thanks for the help. |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
 |
Quan Chi2 Member of "Sexy Teenagers that Code" Group

Age:34 Gender: Joined: Mar 25 2005 Posts: 860 Location: NYC Offline
|
Posted: Thu Sep 15, 2005 4:20 pm Post subject: |
 |
|
|
|
hmmm I normally use text files.. I should start using ini files  |
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: 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. |
|
Back to top |
|
 |
Quan Chi2 Member of "Sexy Teenagers that Code" Group

Age:34 Gender: Joined: Mar 25 2005 Posts: 860 Location: NYC Offline
|
Posted: Thu Sep 15, 2005 6:15 pm Post subject: |
 |
|
|
|
um.. or you can just code it so that the bot reads from memory right? |
|
Back to top |
|
 |
BDwinsAlt Agurus's Posse

Age:34 Gender: Joined: Jun 16 2003 Posts: 1145 Location: Alabama Offline
|
Posted: Thu Sep 15, 2005 7:03 pm Post subject: |
 |
|
|
|
Java....
Oh i mean Suuuurrrreeeee, lets go with that  |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: 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 |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. |
|
Back to top |
|
 |
Cerium Server Help Squatter

Age:42 Gender: Joined: Mar 05 2005 Posts: 807 Location: I will stab you. Offline
|
Posted: Thu Sep 15, 2005 11:27 pm Post subject: |
 |
|
|
|
Does the file get opened/closed on each call to GetPrivateProfileString? _________________ There are 7 user(s) ignoring me right now. |
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: 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  |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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.  |
|
Back to top |
|
 |
Quan Chi2 Member of "Sexy Teenagers that Code" Group

Age:34 Gender: Joined: Mar 25 2005 Posts: 860 Location: NYC Offline
|
Posted: 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 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 |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. |
|
Back to top |
|
 |
Quan Chi2 Member of "Sexy Teenagers that Code" Group

Age:34 Gender: Joined: Mar 25 2005 Posts: 860 Location: NYC Offline
|
Posted: Fri Sep 16, 2005 6:57 pm Post subject: |
 |
|
|
|
whats causing the open and close speed? |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Fri Sep 16, 2005 11:27 pm Post subject: |
 |
|
|
|
Figure it out, it's already been said. |
|
Back to top |
|
 |
Underlord Novice
Gender: Joined: Feb 17 2004 Posts: 55 Offline
|
Posted: Sun Sep 18, 2005 8:53 pm Post subject: |
 |
|
|
|
Sample Code to retrieve settings from a .ini file
#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
// [Bot] is from first argument in GetPrivateProfileString
// ArenaName= is second
[Bot]
ArenaName=league
MaxDeaths=3
|
|
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: 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:
//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);
...
} |
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. |
|
Back to top |
|
 |
|