Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
How to save/read to/from an outside file?

 
Post new topic   Reply to topic Printable version
 View previous topic  Custom CTF Bot/MervPlugin (Flag starts... Post :: Post Is there a way to turn bullets off..?  View next topic  
Author Message
LearJett+
Server Help Squatter


Joined: Jul 11 2005
Posts: 281
Offline

PostPosted: Wed Sep 14, 2005 7:52 pm    Post subject: How to save/read to/from an outside file? Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Wed Sep 14, 2005 8:17 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Wed Sep 14, 2005 10:41 pm    Post subject: Reply to topic Reply with quote

He said merv. I Recommend using GetPrivateProfileString if you're running it on windoze as its the easiest
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
LearJett+
Server Help Squatter


Joined: Jul 11 2005
Posts: 281
Offline

PostPosted: Wed Sep 14, 2005 10:53 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Sep 15, 2005 12:30 am    Post subject: Reply to topic Reply with quote

I recommend http://www.gamedev.net/reference/articles/article1127.asp
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Thu Sep 15, 2005 2:47 am    Post subject: Reply to topic Reply with quote

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)
_________________
Nickname: Maverick (I changed my name!)
TWCore developer | Subspace statistics
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Thu Sep 15, 2005 4:01 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:34
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Thu Sep 15, 2005 4:20 pm    Post subject: Reply to topic Reply with quote

hmmm I normally use text files.. I should start using ini files biggrin.gif
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Thu Sep 15, 2005 5:09 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:34
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Thu Sep 15, 2005 6:15 pm    Post subject: Reply to topic Reply with quote

um.. or you can just code it so that the bot reads from memory right?
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
BDwinsAlt
Agurus's Posse


Age:34
Gender:Gender:Male
Joined: Jun 16 2003
Posts: 1145
Location: Alabama
Offline

PostPosted: Thu Sep 15, 2005 7:03 pm    Post subject: Reply to topic Reply with quote

Java....

Oh i mean Suuuurrrreeeee, lets go with that sa_tongue.gif
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Sep 15, 2005 7:48 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List AIM Address
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Thu Sep 15, 2005 10:37 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Cerium
Server Help Squatter


Age:42
Gender:Gender:Male
Joined: Mar 05 2005
Posts: 807
Location: I will stab you.
Offline

PostPosted: Thu Sep 15, 2005 11:27 pm    Post subject: Reply to topic Reply with quote

Does the file get opened/closed on each call to GetPrivateProfileString?
_________________
There are 7 user(s) ignoring me right now.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Fri Sep 16, 2005 7:05 am    Post subject: Reply to topic Reply with quote

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
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Sep 16, 2005 3:59 pm    Post subject: Reply to topic Reply with quote

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
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:34
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Fri Sep 16, 2005 5:02 pm    Post subject: Reply to topic Reply with quote

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
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Sep 16, 2005 6:48 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:34
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Fri Sep 16, 2005 6:57 pm    Post subject: Reply to topic Reply with quote

whats causing the open and close speed?
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Sep 16, 2005 11:27 pm    Post subject: Reply to topic Reply with quote

Figure it out, it's already been said.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Underlord
Novice


Gender:Gender:Male
Joined: Feb 17 2004
Posts: 55
Offline

PostPosted: Sun Sep 18, 2005 8:53 pm    Post subject: Reply to topic Reply with quote

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
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Thu Sep 22, 2005 3:09 am    Post subject: Reply to topic Reply with quote

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);

   ...   
}
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Thu Sep 22, 2005 4:02 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 13 page(s) served in previous 5 minutes.

phpBB Created this page in 0.525321 seconds : 47 queries executed (92.5%): GZIP compression disabled