Problem with stock
#1

Hello everyone,
I haven't made any thread for a while because I did not actually have any problem until today.
I tried to fix it, I had some researches on the ******/samp forum but still nothing.

I made a stock that it reads a value from 0 to 2147483647 and it prints according to the digits. For example, if I type 10000000 (which is 10 millions), it will display that it's '10M'. However, if I define the variables and print them, they got printed, unless I use the 'ConvertMoney( value );', which prints only until 1BN (billion). Even if it is 2 billions, it doesn't get printed for an unknown reason.

pawn Код:
main( )
{
    new
        a = 1000000000,
        b = 2147483647
    ;
    printf( "a = %d, b = %d", a, b );
    printf( "a = %s", ConvertMoney( a ) );
    printf( "b = %s", ConvertMoney( b ) );
}
The results:

It does not work with over 2 billions and the limit is 2147483647, I can't understand why it doesn't work.
pawn Код:
stock ConvertMoney( value )
{
    new
        tmp[ 128 ],
        val[ 8 ],
        val2[ 16 ]
    ;
    if( value >= 0 && value <= 2147483647 )
    {

        // Converting part
        format( tmp, 128, "%s%s", val2, val );
    }
    else format( tmp, 128, "--" );
    return tmp;
}
Reply
#2

You should show your "converting part" because that's where the problem is.
Reply
#3

Edit: pending..
Reply
#4

Seems like valstr doesn't like numbers that large.

pawn Код:
else if( value >= 1000000000 )
{
    format( val, sizeof( val ), "BN" );
    valstr( val2, value );//problem line.
    if( value >= 1000000000 && value <= 2147483647 ) strdel( val2, 1, 10 );
}
That hangs my server indefinitely when used with the number 2 billion.

EDIT: I thought i remembered correctly, there is a fix in this include by ****** & Co. https://sampforum.blast.hk/showthread.php?tid=292813
Reply
#5

Well, I am not able to test it right now, but I will definetely try that include. I show that valstr can crash the server, so I will test it and I'll reply back!

EDIT: I used that include and it works! And I was sure that I didn't do anything incorrect.
Thanks a lot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)