Thread

Bot logging... (Sdk)

Bot logging... // Sdk

1  |  

veleno

Oct 20, 1998, 6:57pm
Alright... I've gotten my bot to do what I want him to (finally!) but
I'm just wondering how I would get him to log to a text file... in
essence, the same as the world server does...

edward sumerfield

Oct 20, 1998, 9:44pm
These days you have to specify the language you are programming in. This is
such a diverse SDK that its hard to tell.

Let me assume C.

#include <stdio.h>
main() {

FILE *log_file;
char *text="the meaning of life the world and everythin is";

log_file = fopen("log_file.txt", "w+");
if (!log_file) {
printf("Doh.");
} else {
fprintf(log_file, "This is writting to the log file: %s %d.\n",
text, 42);
close(log_file);
}
}

Edward Sumerfield.

[View Quote]

jw

Oct 20, 1998, 10:15pm
or in c++

function()
....
ofstream outfile("chat.log", ios::app); //opens a file to append(add) to
outfile << "written to file" << endl; //adds text to the end, much like
cout
....
outfile.close() //i think this is correct
}


[View Quote] > These days you have to specify the language you are programming in. This is
> such a diverse SDK that its hard to tell.
>
> Let me assume C.
>
> #include <stdio.h>
> main() {
>
> FILE *log_file;
> char *text="the meaning of life the world and everythin is";
>
> log_file = fopen("log_file.txt", "w+");
> if (!log_file) {
> printf("Doh.");
> } else {
> fprintf(log_file, "This is writting to the log file: %s %d.\n",
> text, 42);
> close(log_file);
> }
> }
>
> Edward Sumerfield.
>
[View Quote]

veleno

Oct 21, 1998, 6:46pm
I got this program you listed here to work, but how would I get the bot to....
for instance, greet people and then log the event to the file?

[View Quote] > These days you have to specify the language you are programming in. This is
> such a diverse SDK that its hard to tell.
>
> Let me assume C.
>
> #include <stdio.h>
> main() {
>
> FILE *log_file;
> char *text="the meaning of life the world and everythin is";
>
> log_file = fopen("log_file.txt", "w+");
> if (!log_file) {
> printf("Doh.");
> } else {
> fprintf(log_file, "This is writting to the log file: %s %d.\n",
> text, 42);
> close(log_file);
> }
> }
>
> Edward Sumerfield.
>
[View Quote]

jw

Oct 21, 1998, 8:16pm
fprintf(log_file, "message here as in printf")

[View Quote] > I got this program you listed here to work, but how would I get the bot to....
> for instance, greet people and then log the event to the file?
>
[View Quote]

edward sumerfield

Oct 22, 1998, 12:41am
All you have to do is make sure that that each part of the small program
goes in the right place in the greeter bot.

I will use pseudo code to make it quick but it is the same as the sample
proggie.

main {
aw_init
aw_create
aw_login
aw_enter
fopen();
set position

set chat callback.

while aw_wait {
}

aw_destroy
close();
}

chat callback {

get chat message
fprintf(log, "Saw chat '%s'.\n", chat message);
}

Edward Sumerfield.

[View Quote]

jw

Oct 22, 1998, 9:23am
there is a problem with your code: scope. the file variable can only be used in
the main program in your example. here are the changes:
main {
aw_init
aw_create
aw_login
aw_enter
set position

set chat callback.

while aw_wait {
}

aw_destroy
close();
}

chat callback {

fopen(); //you have to do this in every function you want to be able
to save
get chat message
fprintf(log, "Saw chat '%s'.\n", chat message);
}


[View Quote] > All you have to do is make sure that that each part of the small program
> goes in the right place in the greeter bot.
>
> I will use pseudo code to make it quick but it is the same as the sample
> proggie.
>
> main {
> aw_init
> aw_create
> aw_login
> aw_enter
> fopen();
> set position
>
> set chat callback.
>
> while aw_wait {
> }
>
> aw_destroy
> close();
> }
>
> chat callback {
>
> get chat message
> fprintf(log, "Saw chat '%s'.\n", chat message);
> }
>
> Edward Sumerfield.
>
[View Quote]

walter knupe

Oct 22, 1998, 7:14pm
Don't use fopen everytime you write a log line unless you use fclose() in
the same function to close the file again.

its more efficient to keep the log filehandle variable at global scope

FILE *logfile;

main()
{
logfile = fopen ("mylog.txt", "a"); // "w" overwrites "a" appends
to existing log
if (!logfile)
{
printf("warning: can't open logfile for writing. no log is written
in this session\n");
}
aw_init
aw_create
aw_login
aw_enter
set position

set chat callback.

while aw_wait {
}

aw_destroy
if (logfile) fclose(logfile);
close();
}

chat callback
{
get chat message
if (logfile)
{
fprintf(logfile, "Saw chat '%s'.\n", chat message);
}
}

Jw schrieb in Nachricht <362F15A0.AD930AA5 at mediaone.net>...
>there is a problem with your code: scope. the file variable can only be
used in
>the main program in your example. here are the changes:
>main {
> aw_init
> aw_create
> aw_login
> aw_enter
> set position
>
> set chat callback.
>
> while aw_wait {
> }
>
> aw_destroy
> close();
>}
>
>chat callback {
>
> fopen(); //you have to do this in every function you want to be
able
>to save
> get chat message
> fprintf(log, "Saw chat '%s'.\n", chat message);
>}
>
>
[View Quote]

jw

Oct 22, 1998, 7:19pm
i told you, this doesnt work. as soon as you call another function, the variable
logfile goes out of scope. i hope you know what scope means.

[View Quote] > Don't use fopen everytime you write a log line unless you use fclose() in
> the same function to close the file again.
>
> its more efficient to keep the log filehandle variable at global scope
>
> FILE *logfile;
>
> main()
> {
> logfile = fopen ("mylog.txt", "a"); // "w" overwrites "a" appends
> to existing log
> if (!logfile)
> {
> printf("warning: can't open logfile for writing. no log is written
> in this session\n");
> }
> aw_init
> aw_create
> aw_login
> aw_enter
> set position
>
> set chat callback.
>
> while aw_wait {
> }
>
> aw_destroy
> if (logfile) fclose(logfile);
> close();
> }
>
> chat callback
> {
> get chat message
> if (logfile)
> {
> fprintf(logfile, "Saw chat '%s'.\n", chat message);
> }
> }
>
> Jw schrieb in Nachricht <362F15A0.AD930AA5 at mediaone.net>...
> used in
> able
> This
> %d.\n",

dthknight

Oct 22, 1998, 8:24pm
My shaky knowledge of C says it doesn't... in the example below, I *think* a is
accessible everywhere, b only in the main() function, and c, xx, and yy (the latter
two parameters) from within the xyz() function. Therefore, logfile should be
accessible everywhere.

int a;

int xyz(int xx, int yy);

main ()
{
int b;
// code
}

int xyz (int xx, int yy)
{
float c;
// code
}

[View Quote] > i told you, this doesnt work. as soon as you call another function, the variable
> logfile goes out of scope. i hope you know what scope means.
>
[View Quote]

jw

Oct 22, 1998, 9:06pm
let me try to explain it easily. a variable declared outside of a function is called
global, and all functions have acess to it. a variable declared inside or in the
parameters of a function are local, and are for that function only. they cant be used
in any other function. thus, when you declare logfile in main, you can only use it in
main. as soon as you enter another function, logfile is unreachable, unless you pass a
pointer to it, which im not gonna get into. i reccomend you check out some internet
references/courses to help you with that. btw, scope is whether a variable can be
acessed globally or locally

[View Quote] > My shaky knowledge of C says it doesn't... in the example below, I *think* a is
> accessible everywhere, b only in the main() function, and c, xx, and yy (the latter
> two parameters) from within the xyz() function. Therefore, logfile should be
> accessible everywhere.
>
> int a;
>
> int xyz(int xx, int yy);
>
> main ()
> {
> int b;
> // code
> }
>
> int xyz (int xx, int yy)
> {
> float c;
> // code
> }
>
[View Quote]

dthknight

Oct 22, 1998, 9:43pm
*ahem* both Walter and me said exactly what you said just in code terms - both Walter's
"FILE *logfile;" and my "int a;" examples are declared before main, outside of a function,
and thus are globally acessible variables. I know this and I haven't even got to the
'variable scope' part of my C book yet (although I think I did read it once, just haven't
done the examples etc. there)

[View Quote] > let me try to explain it easily. a variable declared outside of a function is called
> global, and all functions have acess to it. a variable declared inside or in the
> parameters of a function are local, and are for that function only. they cant be used
> in any other function. thus, when you declare logfile in main, you can only use it in
> main. as soon as you enter another function, logfile is unreachable, unless you pass a
> pointer to it, which im not gonna get into. i reccomend you check out some internet
> references/courses to help you with that. btw, scope is whether a variable can be
> acessed globally or locally
>
[View Quote]

jw

Oct 22, 1998, 10:37pm
ok. i just wasnt sure. i didnt quite understand your response, so i wrote this one to make
sure. but i can see you do.

[View Quote] > *ahem* both Walter and me said exactly what you said just in code terms - both Walter's
> "FILE *logfile;" and my "int a;" examples are declared before main, outside of a function,
> and thus are globally acessible variables. I know this and I haven't even got to the
> 'variable scope' part of my C book yet (although I think I did read it once, just haven't
> done the examples etc. there)
>
[View Quote]

jw

Oct 22, 1998, 10:43pm
Walter, i owe you an apology. i did not notice the decleration of the variable outside the
main. if you do it the way you did, then it works.

[View Quote] > *ahem* both Walter and me said exactly what you said just in code terms - both Walter's
> "FILE *logfile;" and my "int a;" examples are declared before main, outside of a function,
> and thus are globally acessible variables. I know this and I haven't even got to the
> 'variable scope' part of my C book yet (although I think I did read it once, just haven't
> done the examples etc. there)
>
[View Quote]

edward sumerfield

Oct 23, 1998, 1:00am
So we all agree then? Cool.

Veleno, I hope you got all that.

Edward Sumerfield.

[View Quote]

walter knupe

Oct 23, 1998, 1:53pm
Jw schrieb in Nachricht <362FD130.33BE812C at mediaone.net>...
>Walter, i owe you an apology. i did not notice the decleration of the
variable outside the
>main. if you do it the way you did, then it works.

That's ok :)

Walter

veleno

Oct 23, 1998, 6:43pm
Yes, I got it... didn't take me very long once I sorted out all of the
messages... hehe... I appreciate all of your help and replies... The Bot Logging
works... :)

[View Quote] > So we all agree then? Cool.
>
> Veleno, I hope you got all that.
>
> Edward Sumerfield.
>
[View Quote]

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn