Author Topic: Help (first time coding)?  (Read 1540 times)


Wow thanks a lot Trinick, really helps. I am slowly beginning to understand this stuff now.

I shamelessly ripped and edited the spam prevention part from a code written by Advanced Bot a while back. I'm not sure if it's right.

Code: [Select]
function showRuntime()
{
%runtime = getSimTime();
%runtime = mFloor(%runtime / 1000)
%runtime = getTimeString(%runtime)
%announce("Blockland has been running for" @ %runtime)
{
%client.lastAnnounce
if ($Sim::Time - %client.lastThanksTime > 10000)
{
%announce("Blockland has been running for @ %runtime")
}
else
{
%client.chatMessage("\c6You are doing that too much.");
}
}
};
« Last Edit: March 16, 2014, 01:04:11 AM by Muslim »

Wow thanks a lot Trinick, really helps. I am slowly beginning to understand this stuff now.

I shamelessly ripped and edited the spam prevention part from a code written by Advanced Bot a while back. I'm not sure if it's right.

Code: [Select]
-codesnip-

You're getting there but you still need to learn a few things. Check mine against yours to see what you did wrong:

function serverCmdShowRunTime(%client)
{
   %simTime = getSimTime();
   
   if(%simTime - %client.runTimeDelay > 1000)
   {
      %client.runTimeDelay = %simTime;

      %time = %simTime;
      %time = mFloor(%time / 1000);
      %time = getTimeString(%time);

      announce("Blockland has been running for \c6" @ %time @ ".");
      return true;
   }
   else
   {
      %client.chatMessage("\c6You are doing that too much.");
      return false;
   
}

}

Code: [Select]
function serverCmdShowRunTime(%client)
{
%simTime= getSimTime();

if(%simTime - %client.runTimeDelay > 1000)
{
%time = %simTime();
%time = mFloor(%time / 1000)
%time = getTimeString(%time)

%announce("Blockland has been running for" @ %runtime)
return true;
}
else
{
%client.chatMessage("\c6You are doing that too much.")
return false;
}

};

I think I'm getting there. I fixed everything that I had done wrong, and now I see it makes a lot more sense.

Code: [Select]
function serverCmdShowRunTime(%client)
{
%simTime= getSimTime();

if(%simTime - %client.runTimeDelay > 1000)
{
%time = %simTime();
%time = mFloor(%time / 1000)
%time = getTimeString(%time)

%announce("Blockland has been running for" @ %runtime)
return true;
}
else
{
%client.chatMessage("\c6You are doing that too much.")
return false;
}

};

I think I'm getting there. I fixed everything that I had done wrong, and now I see it makes a lot more sense.

There is still an error in there.

Found it and corrected it!

Code: [Select]
function serverCmdShowRunTime(%client)
{
%simTime= getSimTime();

if(%simTime - %client.runTimeDelay > 1000)
{
%time = %simTime;
%time = mFloor(%time / 1000)
%time = getTimeString(%time)

%announce("Blockland has been running for" @ %runtime)
return true;
}
else
{
%client.chatMessage("\c6You are doing that too much.")
return false;
}

};
In yours, there's no ; at the end. But everyone has told me to add one at the end.

Code: [Select]
function serverCmdShowRunTime(%client)
{
%simTime= getSimTime();

if(%simTime - %client.runTimeDelay > 1000)
{
%time = %simTime;
%time = mFloor(%time / 1000)
%time = getTimeString(%time)

%announce("Blockland has been running for" @ %runtime)
return true;
}
else
{
%client.chatMessage("\c6You are doing that too much.")
return false;
}

};
In yours, there's no ; at the end. But everyone has told me to add one at the end.
There should not be an ; at the end of a function declaration. Only at the end of creating an object or package. There should also be an ; at the end of lines 7, 8, and 10(counting the first line as line 0). Also, line 10 should not have a % at the beginning, as you are calling a function.

; doesn't come at the end of every line, just most lines.

The only lines that don't end in ; are called declarations. Brackets also don't end in semicolons (usually) because they're not really lines of code. Since } at the end of your script closes a function declaration (serverCmdShowRunTime) it doesn't get a semicolon. Another example of a declaration is an if statement, so lines that start with "if" don't get semicolons either. "else" works the same way. All other lines in your script deserve a semicolon.

So you are saying that
This has no errors at all? Are you saying you know more than us?! What?

I don't know why it matters of who helps who first, the more help he gets, the better. Your little code didn't really help.

I really didn't give a stuff who helped him first. I said go look through already made things and look for what I talked about. Where the hell did you even get "Are you saying you know more than us"? I just said this pedantic whining is pretty annoying.

I really didn't give a stuff who helped him first. I said go look through already made things and look for what I talked about. Where the hell did you even get "Are you saying you know more than us"? I just said this pedantic whining is pretty annoying.
Hey, you have a problem.

Are you people serious? I gave him a super simple explanation of what to look for. Y'all motherforgeters are pedantic as stuff..

Look at what you said, who has the problem now?



if, else, else if, for, while, and possibly a few more do not need a ; at the end.

A ; at the end of brackets are only needed if you are creating an object or a datablock, such as,

$Robot = new AIPlayer()
{
    hates_everyone = true;
    belongsInJail = true;
    type = "Awesome Robot";
    name = "Robot";
};
« Last Edit: March 17, 2014, 07:21:59 PM by Advanced Bot »

It's worth noting that when you're creating an object, the brackets don't exactly signify the same thing they normally do.  You can drop the brackets entirely for objects that don't need a datablock to be created, and it'll still work just fine.