tag mismatch
#1

Hello everyone,

I've created a new function and when I call it I get the error message as title.

pawn Код:
forward IsDivisible(the_number, divided_by);
public IsDivisible(the_number, divided_by)
{
    while(the_number > 0) the_number -= divided_by;
    if(!the_number) return true;
    return false;
}
pawn Код:
if(IsDivisible(100, 3) == false) // the warning line.
        printf("This value can not be divised by 3");
Please help me about it. Thanks.
Reply
#2

Just wondering, why using this function, when you've got modules?
You can use:
pawn Код:
if(num%3) == 0 //num devides by 3 with no remainder
else //num does not devide by 3 with no remainder.
Way simpler.
Reply
#3

Are you sure that it's working? 'cuz I couldn't make it work. That's why I created the function.
Reply
#4

Quote:
Originally Posted by Emre__
Посмотреть сообщение
Are you sure that it's working? 'cuz I couldn't make it work. That's why I created the function.
Of course.
Module is used many times.
Anyway if you still want to use your function just replace "if(...) == false" with "if(...) == 0".

And show me what you wanted to do with modules that didn't work out for you?
Reply
#5

I changed "== false" to "== 0" and it didn't return any warning messages, so my function is working properly.

pawn Код:
if(100%3) == 0
        printf("This value can not be divised by 3");
What's wrong with the module.
Reply
#6

Quote:
Originally Posted by Emre__
Посмотреть сообщение
I changed "== false" to "== 0" and it didn't return any warning messages, so my function is working properly.

pawn Код:
if(100%3) == 0
        printf("This value can not be divised by 3");
What's wrong with the module.
Okay, after looking up a bit, it appears that pawn has some issues with modulus, and they're not really working.
I was mistaken because I used to use modulus when I scripted in C++, so I thought pawn also supports them.
My bad. Use your function then.
Reply
#7

Thank you for your help.
Reply
#8

Uh, the modulus works just fine. 100 % 3 is 1. Your code is a fail.
Reply
#9

I believe it happens because as you didn't set a tag for the function, it's automaticly "converting" false to 0 and true to 1.

If I'm correct about this, I think putting a bool tag infront of the function would fix this (at least that seems logical to me):
pawn Код:
forward bool:IsDivisible(the_number, divided_by);
public bool:IsDivisible(the_number, divided_by)
{
    while(the_number > 0) the_number -= divided_by;
    if(!the_number) return true;
    return false;
}
But modulus should work just fine, as Vince stated.
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
Uh, the modulus works just fine. 100 % 3 is 1. Your code is a fail.
!
How did I miss that? God O_O
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)