ThreadBoard ArchivesSite FeaturesActiveworlds SupportHistoric Archives |
if statement help..... (Sdk)
if statement help..... // Sdkpc wizardSep 12, 1998, 11:36pm
Hello, I'm kinda a newbie to actually using VC++ so I was wondering if
somebody could help me with an if statement problem I'm having with the SDK. What I'm trying to do is when somebody enters (which executes teh avatar_add part) the bot will check the citizens name or number (I can't figure out how to get either to work...) and if it is a certian one (like PC Wizard or 104065) then it will say a certian message, else it says the regular one that will be used for everyone else. Also: I can't seem to get the aw_world_eject to work right (to get the bot to eject someone when they say something). When I use the example from the website on the aw_world_eject I get errors on the line: if (strstr (aw_string (AW_CHAT_MESSAGE), BAD_WORD)) { saying that strstr is an undeclared identifier and BAD_WORD is also an undeclared identifier.... what am I supposed to do? I copied it straight from the example (as I said, I'm new to VC++) I tried taking out the (strstr and one of the ')' from the end and then changing BAD_WORD to "bad word", It compiled w/o errors then, and I though with the "" it would make it look for that exact word, but now it ejects somebody when they say anything... That's not allways a good thing for a bot to do :) PC Wizard (ICQ-537376) wizardry at home.com http://pcwizard.ml.org edward sumerfieldSep 13, 1998, 2:58am
You say that "strstr" is reported as an unidentified identifier. That means
that is is not regarding it as a function. You should really be getting a linker error here but if this was true then you wouldn't be able to run the program so I must have missunder stood. Its hard to say without seeing the code but you want to be looking at something like this. #define BAD_WORD "shit" ...... if (strstr(aw_string (AW_CHAT_MESSAGE), BAD_WORD)) { found a bad word } else { didn't find a bad word } The quotes around the word are important because it will result in being a pointer to a string which is what the strstr function wants. The function call to aw_string is already returning a string pointer so that is fine. You can also write the if as follows if (NULL != strstr( aw_string(AW_CHAT_MESSAGE), BAD_WORD)) { Some people believe it is easier to read when you specify the actual return value. Edward Sumerfield, esumerfd at poboxes.com http://members.xoom.com/esumerfd [View Quote] roland vilettSep 13, 1998, 6:17pm
I can't say for sure without seeing your code but I'd guess that if the
compiler doesn't like the strstr call it's because you need to include the string.h header file, like this: #include <string.h> If you are brand new to C or C++ programming, I strongly recommend either taking an introductory programming class or buying a teach-yourself-C kind of book. It's certainly possible to figure it all out on your own, but I think most people will have much better luck getting up to speed on C by following some kind of structured tutorial, especially if you are new to programming in general. I should mention that the snippets of sample code spread throughout the API docs are generally not intended to compile on their own. They are there simply to illustrate in as few lines as possible how a certain method or concept is used. The only place where you will find sample code that is complete and compilable without modification is in the separate sample program section. By the way, one thing to remember while playing with the aw_world_eject() method is that eject works by IP address. So if you try to test your bot by running it on your PC and then going in and swearing at it, it will not only eject you but it will eject itself as well. :) -Roland [View Quote] pc wizardSep 13, 1998, 8:10pm
Thanks that let it comile w/o errors... now to test it...
I know about the IP part (of the ejection), thats why I have it set to eject for only 30 seconds, plus the place I'm testing it in I have caretaker so the eject doesn't work, but I can tell when it tries to eject cause I made it say "ejecting" when it does that and it writes it in the world (I'm hosting the world) that someone tried to eject and in the bot window... Oh, and usually I ask somebody to help test it that gets on my nerves sometimes :) I'm not trying to learn C/C++ by myself right now :) just sorta get a little understanding on it (basicly for the sdk right now) next year in school I'm taking a programming class which is in C. PC Wizard (ICQ-537376) http://pcwizard.ml.org wizardry at home.com Worlds I've started/built in- ftopia, hacktech(hi-tech/space worlds) [View Quote] |