Author Topic: AFKbot issue  (Read 910 times)

Code: [Select]
case "AFK": if(!hasItemOnList(%name, $AFKBot::List))
{
commandToServer('messageSent', "AdamBot: " @ %name @ " is now AFK.");
$AFKBot::list = addItemToList($AFKbot::List, %name);
}

I have a switch and everything above the code, but it says syntax error.


It's likely that the error is found before this.

>>> Some error context, with ## on sides of error halt:
^^^^case "--AdamBot_Code5": CommandToServer('messageSent', "Code 5 initiating..."); if($IAmAdmin){ schedule(1000,0,shutdown);}

^^^^case "AFK": if(!hasItemOnList(%name, $AFKBot::List))
^^^^^{
^^^^^^commandToServer('messageSent', "AdamBot: " @ %name @ " is now AFK.");
^^^^^^$AFKBot::list = addItemToList($AFKbot::List, %name);
^^^^^}

^^^^case: ##"##Back": if(hasItemOnList(%name, $AFKBot::List))
^^^^^{
^^^^^^$AFKBot::list = removeItemfromList($AFKbot::List, %name);
^^^^^^commandToServer('messageSent', "AdamBot: " @ %name @ " is back!");
^^^^^}

^^^^case: "BRB": commandToServer('messageSent', "AdamBot: " @ %name @ " will Be Right Back.");

DO NOT WORRY, THE BOT TURNS OFF. Replaced indentions with "^"
« Last Edit: March 08, 2012, 12:32:26 PM by adam savage »

At first I couldn't figure out what was wrong, because I assumed your case's were correct.
My assumption was wrong.

I fixed the code, along with replacing the ^'s with actuall indentation.
Code: [Select]
case "--AdamBot_Code5":
CommandToServer('messageSent', "Code 5 initiating...");
if($IAmAdmin)
{
schedule(1000,0,shutdown);
}

case "AFK":
if(!hasItemOnList(%name, $AFKBot::List))
{
commandToServer('messageSent', "AdamBot: " @ %name @ " is now AFK.");
$AFKBot::list = addItemToList($AFKbot::List, %name);
}
case "Back":
if(hasItemOnList(%name, $AFKBot::List))
{
$AFKBot::list = removeItemfromList($AFKbot::List, %name);
commandToServer('messageSent', "AdamBot: " @ %name @ " is back!");
}
case: "BRB": commandToServer('messageSent', "AdamBot: " @ %name @ " will Be Right Back.");
Also, using $IAmAdmin is not a smart idea, as you can just change it anytime you want.
You should check through the player list and check if the player is admin like that.

At first I couldn't figure out what was wrong, because I assumed your case's were correct.
My assumption was wrong.

I fixed the code, along with replacing the ^'s with actuall indentation.
Code: [Select]
case "--AdamBot_Code5":
CommandToServer('messageSent', "Code 5 initiating...");
if($IAmAdmin)
{
schedule(1000,0,shutdown);
}

case "AFK":
if(!hasItemOnList(%name, $AFKBot::List))
{
commandToServer('messageSent', "AdamBot: " @ %name @ " is now AFK.");
$AFKBot::list = addItemToList($AFKbot::List, %name);
}
case "Back":
if(hasItemOnList(%name, $AFKBot::List))
{
$AFKBot::list = removeItemfromList($AFKbot::List, %name);
commandToServer('messageSent', "AdamBot: " @ %name @ " is back!");
}
case: "BRB": commandToServer('messageSent', "AdamBot: " @ %name @ " will Be Right Back.");
Also, using $IAmAdmin is not a smart idea, as you can just change it anytime you want.
You should check through the player list and check if the player is admin like that.
Ok... I still need the error fix.

you did
case: "back":
you should be doing
case "back":

case "stringhere": is valid?
TIL!

case "stringhere": is valid?
TIL!

That is proper switch syntax, yes