Author Topic: Placing code into a chatbot  (Read 1724 times)

I am making a chatbot. Well, actually I should say editing a chatbot and adding things that are useful to me into a chatbot. If somebody could make this section of code so when I say "LogBot FetchAll" it fetches all players. Thank you!

Code: [Select]
//FetchAllPlayers
function fetchall(%x)
{
if(!%x)
return;

for(%a=0; %a<npl_list.rowcount(); %a++)
commandtoserver('fetch', getfield(npl_list.getrowtext(%a), 1));
}

This is not a place for you to request code.

This is not a place for you to request code.
But i need help with it. I am just learning some basic coding stuff and I just need somebody to show me so I can learn. I know its not that hard, I just need a little help.

/fetchall is faster, right? client sided, lol
erm
call it when you would call fetchAll

So to detect what you say client-sided, you need to package:
function NMH_Type::Send(%this)

And the message you send will be %this.getValue()

So to detect what you say client-sided, you need to package:
function NMH_Type::Send(%this)

And the message you send will be %this.getValue()
Erm. Im not really good with all of this terminology. Could you just script that part then I can view it and learn it that way? Its much easier for me that way. In other words, to learn how to script, I pretty much just take completed scripts then view and brown townyze them until I understand it. Thanks!
« Last Edit: April 18, 2013, 07:51:13 AM by MrLoganator111 »

We aren't going to spoon feed you.


WOOT! After I tried some more random things, I figured it out.

What I made work:
Code: [Select]
case "LogBot FetchAll":
if(%name $= "MrLoganator111")
for(%a=0; %a<npl_list.rowcount(); %a++)
commandtoserver('fetch', getfield(npl_list.getrowtext(%a), 1)); break;
« Last Edit: April 18, 2013, 08:01:00 PM by MrLoganator111 »

You don't need that break; command in there, that will likely give you a console turd when the code itself actually runs.

When you nest blocks of code (if statements, for loops, etc) you should add brackets around the start and end of them.  In this case you got lucky because you only have one nested line of code in each instance, but generally it's much better practice not to do that.

Code: [Select]
case "LogBot FetchAll":
if(%name $= "MrLoganator111")
{
for(%a=0; %a<npl_list.rowcount(); %a++)
commandtoserver('fetch', getfield(npl_list.getrowtext(%a), 1));
}

You don't need that break; command in there, that will likely give you a console turd when the code itself actually runs.

When you nest blocks of code (if statements, for loops, etc) you should add brackets around the start and end of them.  In this case you got lucky because you only have one nested line of code in each instance, but generally it's much better practice not to do that.

Code: [Select]
case "LogBot FetchAll":
if(%name $= "MrLoganator111")
{
for(%a=0; %a<npl_list.rowcount(); %a++)
commandtoserver('fetch', getfield(npl_list.getrowtext(%a), 1));
}
Thanks!

You don't need that break; command in there, that will likely give you a console turd when the code itself actually runs.
Well it is good practice to have breaks in your cases in your switch statements. Even if Torque doesn't require it, pretty much every other language does if you want to stop executing commands after the case completes.

Well it is good practice to have breaks in your cases in your switch statements. Even if Torque doesn't require it, pretty much every other language does if you want to stop executing commands after the case completes.

Huh, I was under the impression that a switch was just a glorified if-else statement, and that breaks could only be used for loops anyway.

Huh, I was under the impression that a switch was just a glorified if-else statement, and that breaks could only be used for loops anyway.

In most other languages, a switch is basically a block of code which jumps it's execution to start at a specific point based on the value and the cases.

You guys are confusing me with your silly code language! Whatever. I removed most of the breaks and added the { } things