Author Topic: Whats wrong with my chatbot? Please fix it and tell me whats wrong.  (Read 1609 times)

What's wrong with my chatbot? Please fix it and tell me whats wrong.
Code: [Select]
package chatbot {
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%fmsg) {
parent::clientCmdChatMessage
if (%msg $= "lol") {
commandToServer('messageSent',"Ahahahahaha... I dont get it.");
     }
if (%msg $= "rofl") {
commandToServer('messageSent',"I still don't see what's funny.");
if (%msg $= "shut up") {
commandToServer('messageSent',"Right back at ya.");
if (%msg $= "fail") {
commandToServer('messageSent',"If you never fail, you never succeed.");

if (%msg $= "spin") {
turnleft(1);

if (%msg $= "stop spin") {
turnleft(0);
if (%msg $= "holdmouse") {
mousefire(1);


}if (%msg $= "releasemouse") {
mousefire(0);
if (%msg $= "getid") {
commandToServer('messageSent',"/getID");

}
};
activatePackage(chatbot);
All help is appreciated

1. Horrid formatting.
2. Same argument (%fmsg) used twice (is there a bad tutorial or something that's telling people to do this? Cuz I swear every single person coming here with help on their chat bot does this)
3. Parent calling needs arguments
4. Change all the ifs after the first to else if. (I don't think that will actually make a difference in this case, but it still bothers me)
5. The processing of slash commands is done client-side, not server-side. Thus, the getid part should just be commandtoserver('getid');
6. A few missing brackets

Will edit with fixed code

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if(%msg $= "lol")
{
commandToServer('messageSent',"Ahahahahaha... I dont get it.");
}
else if(msg $= "rofl")
{
commandToServer('messageSent',"I still don't see what's funny.");
else if(%msg $= "shut up")
{
commandToServer('messageSent',"Right back at ya.");
}
else if(%msg $= "fail")
{
commandToServer('messageSent',"If you never fail, you never succeed.");
{
else if(%msg $= "spin")
{
turnleft(1);
}
else if(%msg $= "stop spin")
{
turnleft(0);
else if(%msg $= "holdmouse")
{
mousefire(1);
}
else if(%msg $= "releasemouse")
{
mousefire(0);
}
else if (%msg $= "getid")
{
commandToServer('getid');
}
}
};
activatePackage(chatbot);

Looks fine
Use this formatting style instead of the one you were using (with opening brackets on the same line), it's easier for beginners to understand and see the brackets, imo
« Last Edit: September 07, 2012, 10:29:12 PM by Headcrab Zombie »

Thanks!
Testing right now.
If it works, I won't edit this post.

Error: Syntax Errors. Please fix it.

Error: Syntax Errors. Please fix it.
      else if(%msg $= "stop spin")
      {
         turnleft(0);

becomes...       else if(%msg $= "stop spin")
      {
         turnleft(0);
      }

Please fix it.

This is not a place where you just go "please fix it", "please make this for me", etc. This is Coding Help, not Suggestions & Requests.

This is not a place where you just go "please fix it", "please make this for me", etc. This is Coding Help, not Suggestions & Requests.

This

I'm not anywhere near a high level of experience in Torquescript, but I would recommend using a switch instead of half a million if else statements.

I'm not anywhere near a high level of experience in Torquescript, but I would recommend using a switch instead of half a million if else statements.
in this case, seconding this notion

I'm not anywhere near a high level of experience in Torquescript, but I would recommend using a switch instead of half a million if else statements.
in this case, thirding this notion

I'm not anywhere near a high level of experience in Torquescript, but I would recommend using a switch instead of half a million if else statements.
It literally doesn't matter at all, both ways are equally acceptable. If he wants to stick with if else, he should remove the brackets though.

It literally doesn't matter at all, both ways are equally acceptable. If he wants to stick with if else, he should remove the brackets though.
I didn't say his way was incorrect, or that my way was better.

I said I recommend it because it's a tad easier, he may not know of switches and therefore I brought up the suggestion.

I didn't say his way was incorrect, or that my way was better.

I said I recommend it because it's a tad easier, he may not know of switches and therefore I brought up the suggestion.
Well you said "half a million if else statenents", but if you used a switch it would be "half a million" case statements...

Well you said "half a million if else statenents", but if you used a switch it would be "half a million" case statements...
It would take up a ton less space though.

Well you said "half a million if else statenents", but if you used a switch it would be "half a million" case statements...
That would be using less space, brackets, and time.