Thread

dialog based bot.... questions & errors (Sdk)

dialog based bot.... questions & errors // Sdk

1  |  

pc wizard

Oct 15, 1998, 12:51am
Hi me again :)

I got the errors from before off (thanks Roland) now I need to know how to
do something :)...

Here's what my bot program is like:

You start it up and a "menu" comes up.. then you press the Bot button and
another dialog box comes up. In that dialog box are 4 edit boxes for the
botsname, citizen#, citizen pp, and the start world. After those are entered
you his the "Start Bot" button. My problem is that I don't know how to
"assign" (don't know the correct word for it) the botname, starting world,
and citpp to a name besides IDC_BOTNAME_EDIT etc.. the cit# what I did was
go to ClassWizard (I'm using VC++) then Member Variables, then assigned a
member variable called m_citpp with the type: int. But what type (or what
do I do) for the other 3? I need something to replace the argv parts of the
login (using Sample #1 for start of coding). I can't use CString (I found
out the hard way cause I didn't know how to do some of this stuff) , when I
use any of the other types listed when I click "Add variable" under member
variables I get an error saying it can't convert it to char *. how would I
do this then? (I'm novice at C/C++ .. :))

Also if possible is there a way to have it print the log (like the printf
lines) to another edit box? (IDC_LOG_EDIT) and put errors into popup message
boxes, since it's not a console app....

thanx to anyone who replies :)

PC Wizard (ICQ-537376)
wizardry at home.com
http://pcwizard.ml.org

edward sumerfield

Oct 15, 1998, 1:33am
May I offer some high level advice. Leave windows alone.

It may be pretty,
it may be cool,
but drat that darn thing,
it'll make you feel like a fool.

I've been programming for 13 years and I still have problems when I get into
that area. Of coarse most of my experience has been in a Unix C environment
but I feel confident in saying that you are entering a very complicated
area.

The problem is that the app wizard you ran is nice and gives you a quick,
basic framework that looks good but now you really have to understand what
it is doing to be able to make it do what you want.

Maybe Walter can give you some advice, he seems to be the Windows guru
around here.

Use argc, argv to start with. Check out the scanf function for user input.
So you might write a program like this.

main() {
int number;
char name[32], priv[32];

printf("Enter user #, Robot name, priv passwd : ");
scanf("%d %s %s", &number, name, priv);

etc.
}

Learn the standard C functions. If you are just starting out learning to
program then you should begin with an object oriented language like Java or
C++. I recommend Java because everything you need is free and it clearly
demonstrates OO design principles.

Edward Sumerfield

[View Quote]

canopus

Oct 15, 1998, 12:25pm
The Delphi programs mentioned above are all windows-based. What you describe
(edit-boxes, log-dumps, etc.) are easy to do in Delphi. I have a SurveyorBot
that takes the Owner#, Priv.Password, botname, appname, world, and X,Y,Z from
editboxes, logs the returns into one MemoBox window, and logs the queried
objects into another List, which is saved to a file of the user's choice in a
SaveDialog window before the main window closes. The user shrinks the AW Browser
window down to the medium-size version, and opens the Bot application, which is
in a bar along the top of the screen. When all the EditBoxes are filled, the
user presses a Start button, just as you suggest. It would have taken five times
as long to do this in C (or C++), as Magine noted.

[View Quote] > Hi me again :)
>
> I got the errors from before off (thanks Roland) now I need to know how to
> do something :)...
>
> Here's what my bot program is like:
>
> You start it up and a "menu" comes up.. then you press the Bot button and
> another dialog box comes up. In that dialog box are 4 edit boxes for the
> botsname, citizen#, citizen pp, and the start world. After those are entered
> you his the "Start Bot" button. My problem is that I don't know how to
> "assign" (don't know the correct word for it) the botname, starting world,
> and citpp to a name besides IDC_BOTNAME_EDIT etc.. the cit# what I did was
> go to ClassWizard (I'm using VC++) then Member Variables, then assigned a
> member variable called m_citpp with the type: int. But what type (or what
> do I do) for the other 3? I need something to replace the argv parts of the
> login (using Sample #1 for start of coding). I can't use CString (I found
> out the hard way cause I didn't know how to do some of this stuff) , when I
> use any of the other types listed when I click "Add variable" under member
> variables I get an error saying it can't convert it to char *. how would I
> do this then? (I'm novice at C/C++ .. :))
>
> Also if possible is there a way to have it print the log (like the printf
> lines) to another edit box? (IDC_LOG_EDIT) and put errors into popup message
> boxes, since it's not a console app....
>
> thanx to anyone who replies :)
>
> PC Wizard (ICQ-537376)
> wizardry at home.com
> http://pcwizard.ml.org

walter knupe

Oct 15, 1998, 7:31pm
Hey PC,

I am answering your question right below :)


PC Wizard schrieb in Nachricht <3625622b.0 at homer>...

>You start it up and a "menu" comes up.. then you press the Bot button and
>another dialog box comes up. In that dialog box are 4 edit boxes for the
>botsname, citizen#, citizen pp, and the start world. After those are
entered
>you his the "Start Bot" button. My problem is that I don't know how to
>"assign" (don't know the correct word for it) the botname, starting world,
>and citpp to a name besides IDC_BOTNAME_EDIT etc.. the cit# what I did was
>go to ClassWizard (I'm using VC++) then Member Variables, then assigned a
>member variable called m_citpp with the type: int. But what type (or what
>do I do) for the other 3? I need something to replace the argv parts of the
>login (using Sample #1 for start of coding). I can't use CString (I found
>out the hard way cause I didn't know how to do some of this stuff) , when I
>use any of the other types listed when I click "Add variable" under member
>variables I get an error saying it can't convert it to char *. how would I
>do this then? (I'm novice at C/C++ .. :))

Well, the answer to all of this is simple, use CString. Thats what i did.
There is only one problem:

CString can be used as any "const char *" because its a C++ class which has
an overloaded casting operator.
BUT the aw_string_set are c style functions, and c style programmers do not
care about the "const" attribute.

this prevents a c++ compiler from letting you use CString as the argument
for aw_string_set.

Roland might change his include file (and his dll source as well) to use
"const char *" whenever he does not need to change the supplied string.

you need a work around which casts the CString to (const char *), and then
to (char *). (assuming, and thats the bad part of it, that aw_string does
_not_ change the supplied string)

that would look like
CString m_loginname = "Daniel";
aw_string_set((char *)(const char *)m_loginname));

and since that looks very ugly, you hide it using a define.

#define AWSTR(param) (char *) (const char *) param


Heres the part from my bot code which sets the login parameters, directly
from the member variables created in class wizard.

aw_int_set (AW_LOGIN_OWNER, m_citizennr); // Faber citizen number
aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, AWSTR(m_privilegepw));
aw_string_set (AW_LOGIN_APPLICATION, AWSTR("Faber Bot App"));
aw_string_set (AW_LOGIN_NAME, AWSTR(m_name));


If you do this in the message handler for a button on the dialog, remember
to call UpdateData(TRUE) first to make sure the class members are in sync
with the dialog controls.


>Also if possible is there a way to have it print the log (like the printf
>lines) to another edit box? (IDC_LOG_EDIT) and put errors into popup
message
>boxes, since it's not a console app....

Sure, create an edit box control on your dialog window, assign a member
variable to it of type CEdit (note its a control association, not a data
transfer) and name it m_status, and add a function (using ClassView, or do
it your own) like follows:

void CDanielDlg::Print(const char * message)
{
CString outmessage;
outmessage.Format("%s\r\n", message); // note the \r which is important
in edit fields
m_status.ReplaceSel(outmessage); // add text to current cursor
position
int start, end;
m_status.GetSel(start, end); // get selection position
m_status.SetSel(end, end); // remove the selection and set cursor at
end of it
}

(taken from the Daniel bot, if you ever ran into it :) i usually carry it
around when i am in aw )

you can call it with constant strings, not const strings or CStrings,
whatever you prefer :)


If its not enough to have errors logged in there, use the MessageBox system
call for it. Inside a window class using MFC the function prototype is

MessageBox(const char *message, const char *title="Error", int style=MB_OK)
so try

MessageBox("Could not log in to AW universe");

for simple boxes or

if (IDYES == MessageBox("error occured, continue?","Please select",
MB_YESNO))
// continue here
else
// do not continue


hope it helped :)

Walter

>
>thanx to anyone who replies :)
>
>PC Wizard (ICQ-537376)
>wizardry at home.com
>http://pcwizard.ml.org
>
>

walter knupe

Oct 15, 1998, 7:37pm
Edward,


Edward Sumerfield schrieb in Nachricht <36256c9b.0 at homer>...
>May I offer some high level advice. Leave windows alone.
>
> It may be pretty,
> it may be cool,
> but drat that darn thing,
> it'll make you feel like a fool.

nah..... i think its cool whatever you are used to...

>
>I've been programming for 13 years and I still have problems when I get
into
>that area. Of coarse most of my experience has been in a Unix C environment
>but I feel confident in saying that you are entering a very complicated
>area.

Nope, its about as difficult as having a real good argc argv parser
(including options with arguments separatet by quotation marks and reversing
and stuff :) )

GUI used to be very complicated (win16 API), but MFC helped alot.

>
>The problem is that the app wizard you ran is nice and gives you a quick,
>basic framework that looks good but now you really have to understand what
>it is doing to be able to make it do what you want.

thats actually true. it makes you feel you could work with VC as you can
with VB, but thats not the case. but thats something you soon discover :)

>
>Maybe Walter can give you some advice, he seems to be the Windows guru
>around here.

oh well, i did and i hope it helped :)

>
>Use argc, argv to start with. Check out the scanf function for user input.
>So you might write a program like this.
>
>main() {
> int number;
> char name[32], priv[32];
>
> printf("Enter user #, Robot name, priv passwd : ");
> scanf("%d %s %s", &number, name, priv);
>
> etc.
>}
>
>Learn the standard C functions. If you are just starting out learning to
>program then you should begin with an object oriented language like Java or
>C++. I recommend Java because everything you need is free and it clearly
>demonstrates OO design principles.

This is really unix background :) Windows things are a different world.
16bit-windows never had a reall command line or at least no documented argc
argv (dos had, but windows didn't).

>
>Edward Sumerfield

roland vilett

Oct 15, 1998, 8:55pm
>Roland might change his include file (and his dll source as well) to use
>"const char *" whenever he does not need to change the supplied string.


I don't believe any strings passed to the API are modified anywhere in the
SDK. The SDK always makes its own copies of everything. Are you saying I
should change all "char *" in the function prototypes to "const char*"? I
can do this easily, if it will help. I have to admit that this is one area
where my knowledge is a bit hazy...

Thanks,
Roland

edward sumerfield

Oct 15, 1998, 11:56pm
Well we all have our preferences and most of that is due to what we know. It
is really cool to see so many versions of this thing developing. Delphi, C,
Java and C++ makes it a good spread of popular languages in todays business
world.

I look forward to having to time to study Windows programming one day. Maybe
I try and adapt someones bot.

[View Quote]

pc wizard

Oct 16, 1998, 12:48am
BIG Thanks! That made my day! (maybe my week :)) But VC++ doesn't like
the return 0; line at the end:
D:\DevStudio\MyProjects\AWTeenBot\AWTeenBotDlg.cpp(246) : error C2562:
'OnStartbotButton' : 'void' function returning a value

I commented it out (just to see what it owuld do then) and it gave me
this:
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_term
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_destroy
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_wait
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_state_change
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_enter
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_login
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_string_set
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_int_set
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_create
AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
__imp__aw_init


PC Wizard (ICQ-537376)
wizardry at home.com
http://pcwizard.ml.org

[View Quote]

pc wizard

Oct 16, 1998, 3:50am
I get this error on the code you geve me to get the log to print to the
edit box:

D:\DevStudio\MyProjects\AWTeenBot\AWTeenBotDlg.cpp(189) : error C2509:
'Print' : member function not declared in 'CAWTeenBotDlg'

This is the code I have in there:
void CAWTeenBotDlg::Print(const char * message)
{
CString outmessage;
outmessage.Format("%s\r\n", message); // note the \r which is
important in edit fields
m_status.ReplaceSel(outmessage); // add text to current cursor
position
int start, end;
m_status.GetSel(start, end); // get selection position
m_status.SetSel(end, end); // remove the selection and set cursor
at end of it
}

PC Wizard (ICQ-537376)
wizardry at home.com
http://pcwizard.ml.org

[View Quote]

walter knupe

Oct 16, 1998, 3:27pm
The attribute "const" is in c is almost code flavour only. the c compiler
does not really care.

in c++ it has become very strict. you can't change what is const and you
can't use something that is const as something that is not const, unless you
cast to it (so that you know whats going on).
and you can depend on the fact that people wont change what you supply as
const.

so i'd say that you actually change your (char *) parameters in your aw.dll
and aw.h to (const char *). recompile it to see if the c compiler complains.
(if you use c++ in there i am quite sure it will, since your code is adapted
to "char *" and not "const char *.)

if it does NOT complain, you are on the safe side and your interface
description is more safe and more accurate for c++, and in that case
DEFINETELY change aw.h in the next sdk build :)

Walter



Roland Vilett schrieb in Nachricht <36267d7a.0 at homer>...
>
>
>I don't believe any strings passed to the API are modified anywhere in the
>SDK. The SDK always makes its own copies of everything. Are you saying I
>should change all "char *" in the function prototypes to "const char*"? I
>can do this easily, if it will help. I have to admit that this is one area
>where my knowledge is a bit hazy...
>

walter knupe

Oct 16, 1998, 3:29pm
if you declare a function as void, it MUST not return a value under c++ ( c,
again, doesn't really enforce this).

so remove the return line, (or at least the value to it, change it to
return; )

for the linker errors, make sure to adapt your project settings to inlude
"aw.lib" as additional libraries in the linkers tab (both for release and
debug version).

Walter


PC Wizard schrieb in Nachricht <3626B401.939B0CB8 at home.com>...
>BIG Thanks! That made my day! (maybe my week :)) But VC++ doesn't like
>the return 0; line at the end:
>D:\DevStudio\MyProjects\AWTeenBot\AWTeenBotDlg.cpp(246) : error C2562:
>'OnStartbotButton' : 'void' function returning a value
>
>I commented it out (just to see what it owuld do then) and it gave me
>this:
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_term
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_destroy
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_wait
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_state_change
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_enter
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_login
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_string_set
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_int_set
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_create
>AWTeenBotDlg.obj : error LNK2001: unresolved external symbol
>__imp__aw_init
>
>
>PC Wizard (ICQ-537376)
>wizardry at home.com
>http://pcwizard.ml.org
>
[View Quote]

walter knupe

Oct 16, 1998, 3:31pm
you forgot to add the function to the class declaration in the corresponding
header file. this is what your class wizard does for you usually, unless you
are adding a function yourself.

open "AWTeenBotDlg.h" and look for the CAWTeenBotDlg class declaration..

in there you find several function and variables definition already,

add a line saying

void Print(const char *message);

to it.

Walter


PC Wizard schrieb in Nachricht <3626DEB0.B9CAAEA8 at home.com>...
>I get this error on the code you geve me to get the log to print to the
>edit box:
>
>D:\DevStudio\MyProjects\AWTeenBot\AWTeenBotDlg.cpp(189) : error C2509:
>'Print' : member function not declared in 'CAWTeenBotDlg'
>
>This is the code I have in there:
>void CAWTeenBotDlg::Print(const char * message)
>{
> CString outmessage;
> outmessage.Format("%s\r\n", message); // note the \r which is
>important in edit fields
> m_status.ReplaceSel(outmessage); // add text to current cursor
>position
> int start, end;
> m_status.GetSel(start, end); // get selection position
> m_status.SetSel(end, end); // remove the selection and set cursor
>at end of it
>}
>
>PC Wizard (ICQ-537376)
>wizardry at home.com
>http://pcwizard.ml.org
>

pc wizard

Oct 16, 1998, 5:08pm
thanks again, now 1 more thing (sorry if this is getting anoying...)
when I run the program now (it compiles w/o any errors or warnings) and
I put in the info (citizen number, citizen password, and bot name) and I
click the StartBot button it sits there for a few seconds then the
program just closes it'sefl without giving any errors.. it just
disappears.

I can send you my code so far if it woud help any.

PC Wizard (ICQ-537376)
wizardry at home.com
http://pcwizard.ml.org

[View Quote]

roland vilett

Oct 16, 1998, 5:17pm
Not sure if this is related to your problem or not, but the world AWTeen is
actually running a 2.1 world server and it was set to not allow any bots in.
I just changed it to allow any bots in (for now). If your bot was trying to
enter AWTeen it would not have worked before about 5 minutes ago.

-Roland

[View Quote]

pc wizard

Oct 16, 1998, 5:46pm
I don't think that's it... it did the same thing when I tried to start
it in my world (wizardry). I click the start button and as soon as I
click another program it disappears or if I just wait long enough
without click it still disappears and doesn't show any errors in the
edit box.

[View Quote]

walter knupe

Oct 16, 1998, 9:01pm
Well,

it would help alot if you'd sent me the code.

use my private email address wak at faber.ping.de and include

all files matching (*.cpp; *.h, *.c; *.dsp; *.dsw; *.clw)

i'll post my results here so that everyone sees it :)

Walter

cyborganic

Oct 16, 1998, 11:23pm
Unless your program is multithreaded, another possibility is that it goes
through all the code and closes. I seem to remember Roland saying that
aw_wait() blocks until a message is recieved, so you have to put it in its
own thread in order to use your program while running aw_* functions.
Otherwise, I'm not sure...

Hope it helps,
[ cyborganic ][ prosania at exeter.edu ]

[View Quote]

walter knupe

Oct 17, 1998, 12:46pm
PCWizard,

i have examined your code and fixed a couple of things in it.

first of all, your bot programm could not log in because you didn't call
UpdateData(TRUE) as i mentioned in my post, which caused your member
variables to be empty and your bot trying to login using "" as the name,
resulting in "name to short" error reason code.

you could not see the error message because you didn't use the Print
function that was supplied by me, you still used printf().

your programm exited immediately because you called exit() after error
output, which is something you don't do on windows.you return from the
function instead.

i fixed all this, and it runs just fine now. I startet it and it send itself
to awteens world. i could not enter there using AW browser (access denied)
so i sent my own bot after yours, and i could verify that awteensbot
actually appeared there.


additionally i fixed the following things:

- I changed your log output edit field to include the "multiline parameter"
- the aw_init and aw_term / aw_destroy moved into the application class
because thats where they belong unless
you run multiple bots (in thats case aw_destroy is need for each bot)
- i added the code lines to save your dialog contents into an ini file. the
windows api creates and maintains an "awteenbot.ini" file now in the windows
directory
- i gave an example for parameter checking when using CString
- i included "aw.lib" for debug compilation

and, most important
- i removed the aw_wait(-1) from your bot startup function. instead I added
a timer which is called by windows every second, and in the timer handler it
calles aw_wait(10). that results into your GUI and your bot beeing
responsive.

all my changes are marked with "WAK"

regards,

wak

Walter Knupe schrieb in Nachricht <3627d0e3.0 at homer>...
>Well,
>
>it would help alot if you'd sent me the code.
>
>use my private email address wak at faber.ping.de and include
>
>all files matching (*.cpp; *.h, *.c; *.dsp; *.dsw; *.clw)
>
>i'll post my results here so that everyone sees it :)
>
>Walter
>
>
I
>
>
>

pc wizard

Oct 17, 1998, 1:49pm
Wow, thanks a bunch! I don't know how I missed those things you said I
forgot to put in... I read the NG message 3 times to make sure I had
everthing.. must have read to fast.

PC Wizard
wizardry at home.com
http://pcwizard.ml.org

[View Quote]

canopus

Oct 21, 1998, 5:21pm
Also, for programmers trying to do a windows-based version of these bot
programs, there may be a puzzling window freeze-up when you use aw_query and
callbacks, as some of the other replies have suggested. I don't know if it has
general application, but I found that in Delphi I could break out of a callback
and event loop (as in Sample 2) by inserting an Application.ProcessMessages line
in the loop, followed by a line that tested the state of a Button-controlled
variable. Application.ProcessMessages is just a Delphi-wrapped WinAPI call, I
think. (See below under Build7-Delphi.)

[View Quote] > Hi me again :)
>
> I got the errors from before off (thanks Roland) now I need to know how to
> do something :)...
>
> Here's what my bot program is like:
>
> You start it up and a "menu" comes up.. then you press the Bot button and
> another dialog box comes up. In that dialog box are 4 edit boxes for the
> botsname, citizen#, citizen pp, and the start world. After those are entered
> you his the "Start Bot" button. My problem is that I don't know how to
> "assign" (don't know the correct word for it) the botname, starting world,
> and citpp to a name besides IDC_BOTNAME_EDIT etc.. the cit# what I did was
> go to ClassWizard (I'm using VC++) then Member Variables, then assigned a
> member variable called m_citpp with the type: int. But what type (or what
> do I do) for the other 3? I need something to replace the argv parts of the
> login (using Sample #1 for start of coding). I can't use CString (I found
> out the hard way cause I didn't know how to do some of this stuff) , when I
> use any of the other types listed when I click "Add variable" under member
> variables I get an error saying it can't convert it to char *. how would I
> do this then? (I'm novice at C/C++ .. :))
>
> Also if possible is there a way to have it print the log (like the printf
> lines) to another edit box? (IDC_LOG_EDIT) and put errors into popup message
> boxes, since it's not a console app....
>
> thanx to anyone who replies :)
>
> PC Wizard (ICQ-537376)
> wizardry at home.com
> http://pcwizard.ml.org

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