Author Topic: Need some general help with coding.  (Read 1367 times)

Okay, so i'm fine with the functions of coding, but the real thing that troubles me, is the }'s and {'s.

What i need to know is, what are they for, do they state the end of a function? And where would i put them?

They're called brackets.

{ is an open bracket
} is a closing bracket.

Example using a function:

function myFunction()
{  <--- this starts what you want your function to do
//do stuff
}  <--- this is the end of your function

You need a closing bracket like this }; for closing packages and datablocks. (Correct me if I'm wrong on that last one)

Thank you! Scripting suddenly seems a lot easier. :D

Double toast

Correct me if i'm wrong, but is this a successful script? :D
Code: [Select]
//Stun
//This Script stuns someone

function serverCmdStun (%client)
{
             if(%client.isAdmin == true)
             {

                      echo(" @ %client.name @ " has used the stun command.");
                      if(isObject(findclientbyname(%target).player))
                      {
                                  messageAll('',findclientbyname(%target).name@" was the victim of "@%client.name@"'s stun!");
                                  findclientbyname(%target).player.tumble();
                                  findclientbyname(%target).player.setWhiteOut(1);
                      }
             }
}

Yeah it should work, but change if(%client.isAdmin == true) to  if(%client.isAdmin == true || %client.isSuperAdmin == true)

Okay.
EDIT: Doesn't work.

I type /stun Devvy, and nothing happens. i get no flash, i get no tumble. Halp?
« Last Edit: April 07, 2010, 02:17:42 PM by Devvy »

You don't need the '== true' stuff, just if(%client.isAdmin || %client.isSuperAdmin)


First, I read it "Need some genital help with coding"
Then, I saw your problem.

Code: [Select]
function serverCmdStun (%client, %target)
{
             if(%client.isAdmin || %client.isSuperAdmin)
             {

                      echo(" @ %client.getPlayerName() @ " has used the stun command.");
                      if(isObject(findclientbyname(%target).player))
                      {
                                  messageAll('',findclientbyname(%target).getPlayerName() @" was the victim of " @ %client.getPlayerName() @ "'s stun!");
                                  findclientbyname(%target).player.tumble();
                                  findclientbyname(%target).player.setWhiteOut(1);
                      }
             }
}
You have to put all the variables you want to define using the / at the top part where you declare the function, like I did.
The exception to this is when you do something like
Code: [Select]
%randomPlayer = clientGroup.getObject(getRandom(0,clientGroup.getCount()-1));
Or something that won't be defined using /
Any questions?

Also: If someone is super admin their "admin" variable should also be one, so it really doesn't matter unless you use a terrible mod to admin people (RTB and IGSO are fine) and it only sets their super admin variable.

EDIT: use gameConnection::getPlayerName() instead of gameConnection.name to get their name. %client.name will work, but %client.getPlayerName() will work better.
« Last Edit: April 07, 2010, 05:24:31 PM by Triple Nickels »

:/ Confused. Could you please fix it up for me? Thanks.

Using descriptive variable names helps considerably.  It makes the code easier to understand by you (now and in 6 months), as well as others who are trying to help.

Try this one one for size:
Code: [Select]
function serverCmdStun (%client, %playerName)
  {
   if (%client.isAdmin || %client.isSuperAdmin)
     {
      %stunTarget = findClientByName(%playerName);

      echo(" @ %client.getPlayerName() @ " has used the stun command.");
      if (isObject(%stunTarget.player))
        {
         messageAll('',%stunTarget.getPlayerName() @" was the victim of " @ %client.getPlayerName() @ "'s stun!");
         %stunTarget.player.tumble();
         %stunTarget.player.setWhiteOut(1);
        }
     }
}

Using descriptive variable names helps considerably.  It makes the code easier to understand by you (now and in 6 months), as well as others who are trying to help.

Try this one one for size:
Code: [Select]
function serverCmdStun (%client, %playerName)
  {
   if (%client.isAdmin || %client.isSuperAdmin)
     {
      %stunTarget = findClientByName(%playerName);

      echo(" @ %client.getPlayerName() @ " has used the stun command.");
      if (isObject(%stunTarget.player))
        {
         messageAll('',%stunTarget.getPlayerName() @" was the victim of " @ %client.getPlayerName() @ "'s stun!");
         %stunTarget.player.tumble();
         %stunTarget.player.setWhiteOut(1);
        }
     }
}

Every other script I've seen just leaves it as %player. %playerName could get confusing as you're not targeting the player's name at all, you're targeting the player. I understand what you mean by this however, but at first glance this could throw off new scripters.