Author Topic: Hydrobot v. 1.1  (Read 2445 times)

oh

the p in the hydrobot package is capital

it needs to be lowercase.

How would I combine all the packages into one?
Could you post the code if you know?

Code: [Select]
package hydro
{
   function servercmdmessagesent(%client,%message)
   {
                parent::serverCmdMessageSent(%client,%message);
      if(strlwr(getSubStr(%message,0,2)) $= "hi")
      {
         messageall('',"\c3Hydrobot\c6: Hey there.");
      } elseif(strlwr(%text)$="i hate hydrobot") {
   messageall('',"\c3Hydrobot\c6: I hate you more" SPC %client.name @ ".");
      }
   }
};
activatepackage(hydro);

Thanks pew!
...New error
« Last Edit: October 31, 2010, 09:19:35 PM by FOX TAIL »

Thanks pew!
...New error

Maybe it's the accidental space between the else if and the {

Try replacing the one line with this:


      }elseif(strlwr(%text)$="i hate hydrobot"){


No, spacing around {}s is irrelevant.

The problem is the missing space in the "elseif". It should be "else if".

No, spacing around {}s is irrelevant.

The problem is the missing space in the "elseif". It should be "else if".

Remember: Code spacing can mean the difference between life or syntax error. :panda:

Edit:

Code: [Select]
function findWord(%text, %word) {
for(%i = 0;%i <= getWordCount(%text); %i++)
if(getWord(%text, %i) $= %word)
return %i;
return -1;
}

function HydrobotRespond(%t) {
chatMessageAll("", "\c3Hydrobot\c6: " @ %t);
}

package hydrobot {
function serverCmdMessageSent(%c, %m) {
Parent::serverCmdMessageSent(%c, %m);
if(getWord(%m, 0) $= "hi")
HydrobotRespond("Hey there.");
else if(findWord(%m, "hate") > -1 && findWord(%m, "hydrobot") > findWord(%m, "hate"))
HydrobotRespond("I hate you more" SPC %client.name @ ".");
}
};
activatepackage(hydrobot);

Edit: Fixed code a little.
« Last Edit: November 02, 2010, 12:14:01 AM by MegaScientifical »

Hm. I must be mixed up with some other languages.

Remember: Code spacing can mean the difference between life or syntax error. :panda:
I hate your spacing.


I'm not sure, but doesn't
Code: [Select]
parent::servercmdmessagesent(%client,%text);Need to be right after
Code: [Select]
function servercmdmessagesent(%client,%text){in
Code: [Select]
Package hydroBot?
No.

I'm confused what you mean by this. Tabs?
The fact you put {s on the end of a line of code.

It would only work with VERY consistant spacing, and still is easily confusing.

For people who are still learning, it is best to put the {}s on their own line, like this:

Code: [Select]
function example()
{
    for(%i=0; %i<10; %i++)
    {
        if(%i > 5)
        {
            echo(%i + 1)
        }
        else
          echo(%i SPC "+ 1");
    }
}

It isn't even a good idea to leave single statements without {}s, even though you can (see: The else in the example), until you really understand syntax and can use consistant indenting.

The fact you put {s on the end of a line of code.

Well it's how I learned, and it was from pretty prominent coders. For me, having too many blank areas scares me, but meh. Chrono, if you saw my code files... you'd be crying at how horrific they are.

At one time, my code was extremely ugly, too. Then I left Blockland for a while and just used C.

When a small mistake could mean an unexpected segfault, you quickly learn to make errors obvious. And check all pointers against null. And confirm function parameters, even if "that will never happen", because it is far better that when "never" DOES happen, your code catches it and can respond (probably by giving a clear error log and quitting).

Most importantly: Clarity is critical. If you can easily understand code where the {}s are on the same line as other code, go for it. However, then you rely exclusively on your indentation to quickly identify what code happens when.

Also: Tabs are evil: Everyone sets them differently when they can set them. Use tabs for alignment, use spaces for indentation. That way, if someone uses a different tab width, only the alignment of things like the =s in a large block of assignments or data will be different.

At first I thought the problem was the cs. but I figured out this is TS not C++