Author Topic: Stuck...  (Read 2441 times)

Ok, so I'm scripting a Chatbot (Don't worry I'm scripting it so it won't F*ck up the chat & Respond to every little thing.) that makes Blockland easier, kinda like an assistant! Ok enough about Why lets talk the problem.

Problem:

                        if (%msg $= "Wake Up E3")
                            if(%bl_id $= "12873")
                                {
                                commandToServer('messageSent',"Excella: I'm awake! I'm awake! I was just resting my Powercells...");
                                clientCmdBottumPrint("\c1Excella is |\c4ON\c1|", 3);
                                ActivatePackage(Excella_3);
                                }

No synx errors, the BLID & the clientCmdBottumPrint doesn't work...

Code:

Code: [Select]
package Excella_3_WakeUp
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
        {
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);

                        if (%msg $= "Wake Up E3")
                            if(%bl_id $= "12873")
                                {
    commandToServer('messageSent',"Excella: I'm awake! I'm awake! I was just resting my Powercells...");
                                clientCmdBottumPrint("\c1Excella is |\c4ON\c1|", 3);
                                ActivatePackage(Excella_3);
                                }

                        if (%msg $= "Shutdown E3")
                            if(%bl_id $= "12873")
                                {    
                  commandToServer('messageSent',"Excella: But? Ah, ok.");
                                clientCmdBottumPrint("\c1Excella is |\c2OFF\c1|", 3);
                                DeactivatePackage(Excella_3);
                                }
        }
};
ActivatePackage(Excella_3_WakeUp);

The whole script: http://free.primarypad.com/p/JQf64Tb75N
« Last Edit: June 21, 2014, 10:11:01 PM by Builder/@gent/eventer »

It's because %blid actually is not defined. Literally, it equates to "".
I'm not going to spoon feed you, but that is your first problem.  You also have a bunch of weirdly placed, misplaced, and nonexistent brackets. Also, it's clientCmdBottomPrint. And for anything involving numerical values, you are supposed to use ==, not $=.
One more thing - package Excella_3 does not exist. And chatbots are an easy thing to learn, but they are frowned upon by the community.
« Last Edit: June 21, 2014, 10:15:38 PM by Ninjaman 4 »

Code: [Select]
package Excella_3_WakeUp
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%blid,%cs,%msg)
        {
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%blid,%cs,%msg);

                        if (%msg $= "Wake Up E3")
                            if(%blid $= "12873")
                                {
    commandToServer('messageSent',"Excella: I'm awake! I'm awake! I was just resting my Powercells...");
                                clientCmdBottomPrint("\c1Excella is |\c4ON\c1|", 3);
                                ActivatePackage(Excella_3);
                                }

                        if (%msg $= "Shutdown E3")
                            if(%blid $= "12873")
                                {    
                  commandToServer('messageSent',"Excella: But? Ah, ok.");
                                clientCmdBottomPrint("\c1Excella is |\c2OFF\c1|", 3);
                                DeactivatePackage(Excella_3);
                                }
        }
};
ActivatePackage(Excella_3_WakeUp);

Fixed?

It's because %blid actually is not defined. Literally, it equates to "".
I'm not going to spoon feed you, but that is your first problem.  You also have a bunch of weirdly placed, misplaced, and nonexistent brackets. Also, it's clientCmdBottomPrint. And for anything involving numerical values, you are supposed to use ==, not $=.
One more thing - package Excella_3 does not exist. And chatbots are an easy thing to learn, but they are frowned upon by the community.

Package Excella_3 does exist I just didn't give you my whole Client.cs. I just pasted the link to the whole Client.cs.
Sorry forgot to change Excella_3 to Excella_3_GC!
« Last Edit: June 21, 2014, 10:18:36 PM by Builder/@gent/eventer »

One of the problems is, yes. But there are much more, so no, it is not completely fixed and will still not work.
EDIT: I just looked at the entire client.cs, and there are a lot of things I'll fix for you in five minutes from now. Just remember that || means or, and && means and.
« Last Edit: June 21, 2014, 10:25:39 PM by Ninjaman 4 »

Fixed?
What he means is there is literally NO %BL_ID AT ALL, so not fixed. Instead just use %name. Also I've been going through your code, "DO NOT EDIT THIS FILE UNLIS YOU KNOW WHAT YOU ARE DOING" Are these stupid notes really needed? Also, if they are, you should listen to your own advice. When using the {} characters, the only time you can skip out on them is if ONE line of code is being used right after. Example:
Code: [Select]
if(%name$="friend")
    %client.delete("Not on my watch");
else
    return;

It does not work for
Code: [Select]
if (%msg $= "Shutdown BC")
{
if(%name $= "§gt. ßµïlÐêx")
deactivatePackage(buildChar);
echo("BuildChar has been shutdown.");
commandToServer('messageSent',"Excalla: BuildChar has been De-Activated.");  
}

Also on another note, why not do %name check first, then check %msg. Also a good idea to use else if(%msg$="Blah")

Try this fix on for size.
« Last Edit: June 22, 2014, 11:05:07 AM by Thorfin25 »

Just a word of advice, here - when you are doing

if(%msg $= "Wake Up E3")
{
    if(%name $= "Sgt.Buildex")
    {
        //blah blah blah
    }
}
You should do this instead:

if(%msg $= "Wake Up E3" && %name $= "Sgt.Buildex")

&& means "and", so you don't have to do two different if statements.

It's my own style to rather use multiple statements rather than use && or ||

You should do this instead:
You should do neither of these, at least not in this case.
Check name, then check msg in a nested block. The way he's doing it now, and the way you suggested, makes more comparisons. More comparisons = less efficient, and optimization is a good habit, even when it won't make any noticeable difference

It's my own style to rather use multiple statements rather than use && or ||
Nested ifs can't replace an or, and nested ifs to replace an and looks disgusting with more than two conditions (or arguably even one). You can call it "your own style" as much as you like, but that won't change the fact that any experienced programmer is going to hate it
« Last Edit: June 22, 2014, 11:59:41 AM by Headcrab Zombie »

You should do neither of these, at least not in this case.
Check name, then check msg in a nested block. The way he's doing it now, and the way you suggested, makes more comparisons. More comparisons = less efficient
If you do

if(%msg $= "Wake Up E3" && %name $= "Sgt.Buildex")

and %msg isn't Wake Up E3 then it won't compare %name with Sgt.Buildex

If you do

if(%msg $= "Wake Up E3" && %name $= "Sgt.Buildex")

and %msg isn't Wake Up E3 then it won't compare %name with Sgt.Buildex

It was regarding the fact that there'd probably be several message checks nested within it, I assume. Otherwise, for a common message, it'd be more likely that it wasn't that name rather than it not being that message, and thus it would use one comparison less in most cases.

Nested ifs can't replace an or, and nested ifs to replace an and looks disgusting with more than two conditions (or arguably even one). You can call it "your own style" as much as you like, but that won't change the fact that any experienced programmer is going to hate it

I wrote it for the gist of the statement. And I believe throwing in one extra if at the beginning isn't going to make every experienced programmer hate it. So a few more characters, three more lines, and one more tab. Who cares about it that much?

You should do neither of these, at least not in this case.
Check name, then check msg in a nested block, the way he's doing it now.

If you're talking about what's beyond that link I did that after fixing up his code.

It was regarding the fact that there'd probably be several message checks nested within it, I assume. Otherwise, for a common message, it'd be more likely that it wasn't that name rather than it not being that message, and thus it would use one comparison less in most cases.
Ah, now it makes sense. Yeah he's right then.



You should post the full code in here. An editable document isn't the most ideal solution for the blockland forum.

Thanks guys for the input! Anyway the reason I used blid instead of name is because of this Quote.

Is it possible the error occurs due to the loving crazy name?
Try using %client.bl_id instead of %client.name.

I will post full code on the forum next time.

Anyone who help I would like to say Thank you and I'll put you in my Credits!
If you have a different Blockland name than the forums, please let me know.
Note: the credits below is not the actual credits, the ext had to be changed to upload.


« Last Edit: June 22, 2014, 02:48:13 PM by Builder/@gent/eventer »

I wrote it for the gist of the statement. And I believe throwing in one extra if at the beginning isn't going to make every experienced programmer hate it. So a few more characters, three more lines, and one more tab. Who cares about it that much?
I said hate in the case of
more than two conditions
But even in the case of only two conditions is still less than ideal. Neat code is code that not only does the same thing in the least amount of lines (without sacrificing readability, of course), but also the least number of columns, and adding an unneeded tab here and there adds more columns, especially if you use a text editor like notepad that has HUGE tabs

<download>
You don't need multiple beta testers for simple one-question-one-response chat bot. You test each question, see if it gives the appropriate response, and that's it

Also, if you're the only one who's going to be allowed access to the chatbot, don't use clientCmdChatMessage, instead use NMH_Type::Send(). This is the function that is called when you press enter with a message typed for chat, and thus you don't have to check the name of the sender:

Code: [Select]
package ChatBot
{
function NHM_Type::Send(%this)
{
%msg = %this.getValue();
if(%msg $= "Hello!")
//your bot's response here
}
};
ActivatePackage(ChatBot);

Also look into switches to replace many repeated if...else blocks

But for now I think you should practice on getting formatting and proper bracket usage right
« Last Edit: June 22, 2014, 03:03:37 PM by Headcrab Zombie »

Quote
You don't need multiple beta testers for simple one-question-one-response chat bot. You test each question, see if it gives the appropriate response, and that's it

True, but in my case I've made 3 Guis and a Ui for the MainMenu that need to be tested fully.
I'm just spending too much time on the code, and I need to see if the Guis & Ui works on other computers.
« Last Edit: June 22, 2014, 03:50:45 PM by Builder/@gent/eventer »