Author Topic: why cannot I stop the code here NewChatSO::addLine  (Read 2017 times)

Code: [Select]
package test {
function NewChatSO::addLine(%this, %line) {
%p = parent::addLine(%this, %line);
if(strstr(%line, "asdf") >= 0) {
echo(1);
return;
}
return %p;
}
};
If myself or anyone else in the server types asdf in the chat it echos the 1 but doesn't stop the line from going into my chat.

Code: [Select]
package test {
function NewChatSO::addLine(%this, %line) {
%p = parent::addLine(%this, %line);
if(strstr(%line, "asdf") >= 0) {
echo(1);
return;
}
return %p;
}
};
If myself or anyone else in the server types asdf in the chat it echos the 1 but doesn't stop the line from going into my chat.
When calling the parent of a function basically allows it to run its original code. Move %p = parent::addLine(%this, %line); after the if statement.

Oh thanks that works, I didn't know setting something to a variable did it like that..

Oh thanks that works, I didn't know setting something to a variable did it like that..
It has nothing to do with seeing it to a valuable, the parent:: addline(...) part calls the original code

Oh thanks that works, I didn't know setting something to a variable did it like that..

Just in case you want to read more on how packages work: http://tsforblockland.weebly.com/packages.html

Just in case you want to read more on how packages work: http://tsforblockland.weebly.com/packages.html
I love how you have a chatbot tab, haha

Just in case you want to read more on how packages work: http://tsforblockland.weebly.com/packages.html

I'm trying to think of better ways to word this:
Quote
When a function is initially created, you can use a package and put that function in the package to add code to be executed before or after the original code of the function, or even overwrite that function totally.
Ideas?

Yeah when i wrote that I was like ehhhh, I'll re-word it a bit better. Also, I'm trying to keep it simple for newbies and explain it in a way they can readily understand.

I'm trying to think of better ways to word this:Ideas?

I'm thinking something along the lines of "If a function already exists, you can redefine it inside of a package to extend the original implementation (which can be called from within your version through the Parent:: namespace)." – though that's probably worded a bit too complexly.