Author Topic: Chatbot Help  (Read 2345 times)

You have a lot of serious syntax errors there, and quite a few logic errors.

Wall of text incoming

syntax errors: you forgot to put a semicolen at the end of line 5, you forgot a closing brace on line 14/15, you forgot to put a space between else and if on line 15, you used = to compare 2 values when = is to set a variable (you should've used $=), you improperly used the if statement at "alchbot, generate a [...]", it isn't for formatting an input string, it's for checking values, and even if it did work like that you would've reset it at lines 17 and 18, on which you forgot to put semicolens at the end of, meaning more syntax errors, you put an extra ( on line 19 and again forgot a semicolen, and on line 20 you put @ "" for some reason, idk why.

so about 15 syntax errors
Code: [Select]
//"Alchemy's Person Chatbot" made by Alchemy
//This is a "Medium" script level
//This script was created for "Alchemy"

$owner = "Alchemy";
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if(%name $= $owner && %msg $= "Alchbot, Test Active")
{
commandToServer('messageSent',"[AlchBot]: Activity Test Succeed!");
}
}
else if(%name $= $owner && %msg= "Alchbot, generate a random number between "%a" and "%b"")
{
%a = 0;
%b = 0;
%c = (getRandom(%a,%b))
commandToServer('messageSent',"[Alchbot]: The number returned was "@ %c @");
}
};
activatePackage(Chatbot);
Is this better? I couldn't get it to work. Also, how am I supposed to fix the second if condition?
« Last Edit: July 27, 2012, 12:36:32 PM by PurpleMetro »

dammit your indentation confused me
I meant to say that you didn't end the function the first time, not that you missed a brace on line 15, my mistake there

but you still have a few errors, namely line 16 has around 5. V's indicate errors.
                                        V                                                      V  V      V  V
Code: [Select]
else if(%name $= $owner && %msg= "Alchbot, generate a random number between "%a" and "%b"")
Like I said, you don't use IF's to do input formatting, you use things like getWord(s), getSubStr, etc. for that.

like getWord(%msg, 6) would be %a and getWord(%msg, 8) would be %b

dammit your indentation confused me
I meant to say that you didn't end the function the first time, not that you missed a brace on line 15, my mistake there

but you still have a few errors, namely line 16 has around 5. V's indicate errors.
                                        V                                                      V  V      V  V
Code: [Select]
else if(%name $= $owner && %msg= "Alchbot, generate a random number between "%a" and "%b"")
Like I said, you don't use IF's to do input formatting, you use things like getWord(s), getSubStr, etc. for that.

like getWord(%msg, 6) would be %a and getWord(%msg, 8) would be %b
I don't understand, how am I supposed to put that in the if code?

Well first you check if the first number of words before %a and %b are what you expect, so:
getWords(%msg, 0, 5) $= "Alchbot, generate a random number between"

then

getWord(%msg, 0, 7) $= "and"

and then

getWordCount(%msg) == 8

put that all in a if statement

if(getWords(%msg, 0, 5) $= "Alchbot, generate a random number between" && getWord(%msg, 0, 7) $= "and" && getWordCount(%msg) == 8)

put that in with the name check (btw you should be using $Pref::Player::NetName incase you ever decide to change your name) and you get

else if(%name $= $owner && getWords(%msg, 0, 5) $= "Alchbot, generate a random number between" && getWord(%msg, 0, 7) $= "and" && getWordCount(%msg) == 8)

Well first you check if the first number of words before %a and %b are what you expect, so:
getWords(%msg, 0, 5) $= "Alchbot, generate a random number between"

then

getWord(%msg, 0, 7) $= "and"

and then

getWordCount(%msg) == 8

put that all in a if statement

if(getWords(%msg, 0, 5) $= "Alchbot, generate a random number between" && getWord(%msg, 0, 7) $= "and" && getWordCount(%msg) == 8)

put that in with the name check (btw you should be using $Pref::Player::NetName incase you ever decide to change your name) and you get

else if(%name $= $owner && getWords(%msg, 0, 5) $= "Alchbot, generate a random number between" && getWord(%msg, 0, 7) $= "and" && getWordCount(%msg) == 8)
Still won't work, neither of the commands:
Code: [Select]
//"Alchemy's Personal Chatbot" made by Alchemy
//This is a "Medium" script level
//This script was created for "Alchemy"

$owner = "Alchemy";
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if(%name $= $owner && %msg $= "Alchbot, Test Active")
{
commandToServer('messageSent',"[AlchBot]: Activity Test Succeed!");
}
}
else if(%name $= $owner && getWords(%msg, 0, 5) $= "Alchbot, generate a random number between" && getWord(%msg, 0, 7) $= "and" && getWordCount(%msg) == 8)
{
%a = 0;
%b = 0;
%c = (getRandom(%a,%b))
commandToServer('messageSent',"[Alchbot]: The number returned was "@ %c @");
}
};
activatePackage(Chatbot);

Well that's because you still have syntax errors.
Lines 20 and 21 and 15.

You forgot to move the closing brace from line 15 to the end, line 20 you put in a extra set of brackets (i have no idea why) and forgot a semicolen, line 21 you have a few extra charachters, let me show you:

Code: [Select]
//"Alchemy's Personal Chatbot" made by Alchemy
//This is a "Medium" script level
//This script was created for "Alchemy"

$owner = "Alchemy";
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if(%name $= $owner && %msg $= "Alchbot, Test Active")
{
commandToServer('messageSent',"[AlchBot]: Activity Test Succeed!");
}
else if(%name $= $owner && getWords(%msg, 0, 5) $= "Alchbot, generate a random number between" && getWord(%msg, 0, 7) $= "and" && getWordCount(%msg) == 8)
{
%a = 0;
%b = 0;
%c = getRandom(%a,%b);
commandToServer('messageSent',"[Alchbot]: The number returned was " @ %c);
}
}
};
activatePackage(Chatbot);

ninja: you forgot to put the getWord blocks i mentioned in earlier to get the values of %a and %b so that command won't work

Well that's because you still have syntax errors.
Lines 20 and 21 and 15.

You forgot to move the closing brace from line 15 to the end, line 20 you put in a extra set of brackets (i have no idea why) and forgot a semicolen, line 21 you have a few extra charachters, let me show you:

Code: [Select]
//"Alchemy's Personal Chatbot" made by Alchemy
//This is a "Medium" script level
//This script was created for "Alchemy"

$owner = "Alchemy";
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if(%name $= $owner && %msg $= "Alchbot, Test Active")
{
commandToServer('messageSent',"[AlchBot]: Activity Test Succeed!");
}
else if(%name $= $owner && getWords(%msg, 0, 5) $= "Alchbot, generate a random number between" && getWord(%msg, 0, 7) $= "and" && getWordCount(%msg) == 8)
{
%a = 0;
%b = 0;
%c = getRandom(%a,%b);
commandToServer('messageSent',"[Alchbot]: The number returned was " @ %c);
}
}
};
activatePackage(Chatbot);

ninja: you forgot to put the getWord blocks i mentioned in earlier to get the values of %a and %b so that command won't work
Still won't work. None of the commands do.

Still won't work. None of the commands do.
not even Alchbot, Test Active?
Hmm...

Well i'll think about it, I don't see any syntax errors and I have lots of homework to do ;-;

omg ip you're breaking him

here, let me type this up better

Code: [Select]
$owner = "Alchemy";
package Chatbot
{
function clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg)
{
parent::clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg);
if(%name !$= $owner)
return;
switch$(%msg)
{
case "Alchbot, Test Active":
commandToServer('messageSent',"[AlchBot]: Activity Test Succeed!");
case "Alchbot, generate a random number between":
%a = getWord(%msg, 6);
%b = getWord(%msg, 8);
%c = getRandom(%a,%b);
commandToServer('messageSent',"[Alchbot]: The number returned was " @ %c);
}
}
};
activatePackage(Chatbot);

note how i used switch$()

note how there is a $ in switch$(). there is a switch() version, but that only works with numbers.

if you have any questions, ask.

Why are you sending chat messages? If you're the only person allowed to use it so you can get information for yourself, what's the point of annoying everybody else with messages? Just use NMH_Type::send and add text to the chat HUD instead.

One question, I want to add in support for asking my Alchbot my current status, such as my health, what should I put to return my health value? Is health supposed to be a field/area in the player datablock?
Datablocks are stored server-side, and besides, current health is not stored in them
I don't think there's a way to check current health client-side.

I changed the script a little bit, I set a global string for the owner's name, so checking the name would be easier. It turns out it works
You're better off just comparing it to $Pref::Player::NetName. That way you don't have to change the script if you change your name

-snip-
Switch won't work for what he wants to do with the random numbers. He'd have cut off the numbers in the chat message he sends in order for the case to match, and then he'd have no way to put the numbers in.

Why are you sending chat messages? If you're the only person allowed to use it so you can get information for yourself, what's the point of annoying everybody else with messages? Just use NMH_Type::send and add text to the chat HUD instead.
I agree with you, but let's take this one step at a time
« Last Edit: July 27, 2012, 01:51:38 PM by Headcrab Zombie »

Code: [Select]
$owner = "Alchemy";
package Chatbot
{
function clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg)
{
parent::clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg);
if(%name !$= $owner)
return;
switch$(%msg)
{
case "Alchbot, Test Active":
commandToServer('messageSent',"[AlchBot]: Activity Test Succeed!");
case "Alchbot, generate a random number between":
%a = getWord(%msg, 6);
%b = getWord(%msg, 8);
%c = getRandom(%a,%b);
commandToServer('messageSent',"[Alchbot]: The number returned was " @ %c);
}
}
};
activatePackage(Chatbot);

note how i used switch$()

note how there is a $ in switch$(). there is a switch() version, but that only works with numbers.

if you have any questions, ask.
The active check command works, but the random number command doesn't work. Please help :c

Switch won't work for what he wants to do with the random numbers. He'd have cut off the numbers in the chat message he sends in order for the case to match, and then he'd have no way to put the numbers in.
forget, totally forgot about what i was doing.

forget, totally forgot about what i was doing.
Luggy, :c, help me fix the random number script :c