Author Topic: why won't this function ever return false???  (Read 2339 times)

trying to make a filter for the /setname thing on the bluzone

this thing always returns successful!

Code: [Select]
function strInStr(%str)
{
%parseStr = "forget stuff crap balls <color:";
if(strPos(%parseStr, %str) > -1)
{
return 1;
}
return 0;
}

context
Code: [Select]
if(strInStr(%first) || strInStr(%last) || strInStr(%nick))
{
echo("Test successful.");
return;
}

it /always/ echos "Test successful" then it /never/ returns out of the function!

there are no syntax errors anywhere!
what the forget is going on???

Because it is going to search for the instance of  "forget stuff crap balls <color:". You should loop through each of these words.

Yeah, that is all wrong. I wrote a thing on that rosettacode that does what you need, ill link it in a sec.

Edit: link: http://rosettacode.org/wiki/Search_a_list#TorqueScript
« Last Edit: July 07, 2012, 05:55:39 PM by elm »

Because it is going to search for the instance of  "forget stuff crap balls <color:". You should loop through each of these words.
isn't it the position of string needle in string haystack where strPos(haystack, needle)?
Yeah, that is all wrong. I wrote a thing on that rosettacode that does what you need, ill link it in a sec.

Edit: link: http://rosettacode.org/wiki/Search_a_list#TorqueScript
this will work but why won't mine? (see above)

isn't it the position of string needle in string haystack where strPos(haystack, needle)?
strPos("this is a test forget stuff crap balls <color: end of test","forget stuff crap balls <color:");
==> 15
strPos("this is a test forget crap balls <color: end of test","forget stuff crap balls <color:");
==> -1
strPos("forget","forget stuff crap balls <color:");
==> -1

strPos("this is a test forget stuff crap balls <color: end of test","forget stuff crap balls <color:");
==> 15
strPos("this is a test forget crap balls <color: end of test","forget stuff crap balls <color:");
==> -1
strPos("forget","forget stuff crap balls <color:");
==> -1

but that's not what i'm doing
i'm doing strPos("forget stuff crap balls <color:", "forget");

but that's not what i'm doing
i'm doing strPos("forget stuff crap balls <color:", "forget");
That returns 0.
Also, what were the exact ones that you tested, and what do you mean by "never returns out of the function"?

That returns 0.
Also, what were the exact ones that you tested, and what do you mean by "never returns out of the function"?
it /always/ echos "Test successful"
then after it does this, it sets the players name to the name they tried to set it to, disregarding the return;
just realized my code was set up with the checks in the wrong spot, if I had the strInStr checks in a different spot, no one would be able to set their name.

it works in that regard, but it always returns true

Code: [Select]
messageAll('', '\c6%1\c2 is now \c6%2\c2.', %client.getPlayerName(), %client.getRPName());
bluzoneLog(%client.getplayername() SPC "is now" SPC %client.getRPName(), 1);

if(strInStr(%first) || strInStr(%last) || strInStr(%nick))
{
echo("Test successful.");
return;
}

the problem is it's always telling me "test successful"

Your function always returns true because it is set to return true when it can't find "forget stuff crap balls <color:". I am sure no one would have a name containing the whole string.

It's possible the <color: is somehow screwing it up, try removing that.
You can automatically remove colour, image, etc. tags by using stripMlControlChars on it.

Your function always returns true because it is set to return true when it can't find "forget stuff crap balls <color:". I am sure no one would have a name containing the whole string.
Please leave.
Now.
You have no idea what you're talking about.

Your function always returns true because it is set to return true when it can't find "forget stuff crap balls <color:". I am sure no one would have a name containing the whole string.
i know you're trying to help, but you're misreading this whole thing.
Please leave.
It's possible the <color: is somehow screwing it up, try removing that.
You can automatically remove colour, image, etc. tags by using stripMlControlChars on it.
forgot about this

actually now that i look more closely, the function is always returning true

« Last Edit: July 07, 2012, 07:09:56 PM by Lugnut »

I have 0 idea what the problem is here.

I copy-paste the code into the console, and try StrinStr("blah") and it returns 0.
I try strinstr("forget") and it returns 1.

Wow, just store stuff you dont wan't to a global variable, and use the function i posted above..

Wow, just store stuff you dont wan't to a global variable, and use the function i posted above..
now i really don't know what you mean




OH

here's the problem: %nick is undefined!

it's looking for "" in "forget stuff... whatever" and it's apparently finding it or something.

Code: [Select]
if(strInStr(%first) || strInStr(%last))
{
banBlid(%client.bl_id, -1, "AUTOBAN- ABUSE OF THE /SETNAME FUNCTION (CURSING) (you have no reason for that, srsly)");
return;
}
if(%nick !$= "" && strInStr(%nick))
{
banBlid(%client.bl_id, -1, "AUTOBAN- ABUSE OF THE /SETNAME FUNCTION (CURSING) (you have no reason for that, srsly)");
return;
}
probably works, testing
works
« Last Edit: July 07, 2012, 07:42:42 PM by Lugnut »

By the way you should be using stripos not strpos

I could just use proper case and it'll go straight round your check