Author Topic: Need some help with a script.  (Read 2648 times)

No, it wouldn't work, you forgot a closing parenthesis on line 3.
If you do something like this

"Like this" not copy and paste in.

"Like this" not copy and paste in.
If you want to make the person work instead of spoonfeeding them code, that's fine
But give them psuedocode instead of broken torquescript

3 pages of what used to be a single syntax error

anyways, after taking advice from this topic, this is what I'm at:
Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%cp,%name,%cs,%msg)
{
%msg=%this.getvalue();
if(getWord(%msg,1)$="something");
{
something();
}
}
};
activatePackage(chatbot);

Syntax error:
Code: [Select]
if(getWord(%msg,1)$="something");

remove the ';' at the end of the if statement.

It's working, but it echos the response in the console and doesn't even send the message to the server.

What's the most space saving and efficient way to add other responses?

The script so far:
Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%cp,%name,%cs,%msg)
{
%msg=%this.getvalue();
if(getWord(%msg,1)$="something")
{
commandToServer('messageSent',"trolol");
}
}
};
activatePackage(chatbot);

The console when typing "Something":

Code: [Select]
Add-Ons/Script_LockBot/client.cs (5): Unable to find object: '' attempting to call function 'getValue'
BackTrace: ->[nameSaid]clientCmdChatMessage->[CompassClient]clientCmdChatMessage->[GameBot]clientCmdChatMessage->[chatbot]clientCmdChatMessage

you shouldn't even be using "this.getValue()" because it's clientcmdchatmessage. I don't know what the parameters of that function is, but try getting rid of that line completely

Everything I type goes to the console

Dear god. This topic is going all over the place..

Let me try to clear some things up, without spoon feeding.

First of all, clientCmdChatMessage is a terrible function to be packaging for a chat bot. That is what is called when the server tells you that somebody has said something. You don't want to be sending messages to the server when trying to interact with the bot. Its spammy, annoying, a waste of network communication, and it takes a while when its laggy.
The solution to this is to use the function NMH_Type::Send(%this) and use %this.getValue() to get the message. Then, check if you are talking to your bot, if so, don't call the parent. That way your message wont be sent (you gotta clear the message manually though).

It seems that you don't quite understand how the syntax works, I recommend you go and read through other add-ons. I recommend events, as they usually have no datablocks, and are just pure scripting. Alternatively, go look at another programming language with similar syntax. Javascript is pretty close to Torquescript, go watch a few tutorials on youtube or something until you understand where ; ( ) and { } go.