Jump to content
  • 0
brunosc

Error in changer coin

Question

i got this error when i use @reloadscript 

 This command is deprecated and it will be removed in a future update. Please see the script documentation for an alternative.

    59:         if ( .@num == 0 || .@num >= 2147483647 ) return getarg(0);
    60:         set .@l, getstrlen(""+.@num);
    61:         for ( set .@i,0; .@i < .@l; set .@i, .@i + 1 ) {
*   62:                 set .@num$, .@num % pow(10,.@i+1) / pow(10,.@i) + .@num$;
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    63:                         if ( (.@i+1) % 3 == 0 && .@i+1 != .@l ) set .@num$, ","+ .@num$;
    64:         }
    65:         return .@num$;
[Warning]: script error in file 'npc/custom/meus/tzeny.txt' line 62 column 39
    This command is deprecated and it will be removed in a future update. Please see the script documentation for an alternative.

    59:         if ( .@num == 0 || .@num >= 2147483647 ) return getarg(0);
    60:         set .@l, getstrlen(""+.@num);
    61:         for ( set .@i,0; .@i < .@l; set .@i, .@i + 1 ) {
*   62:                 set .@num$, .@num % pow(10,.@i+1) / pow(10,.@i) + .@num$;
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    63:                         if ( (.@i+1) % 3 == 0 && .@i+1 != .@l ) set .@num$, ","+ .@num$;
    64:         }
    65:         return .@num$;

pow in the future not will be use, but if i change 

 

pow(10,.@i+1) / pow(10,.@i)    ->   (10**.@i+1) / (10**.@i)

 

i dont got error but not show correct zeny in script.

Share this post


Link to post
Share on other sites

8 answers to this question

Recommended Posts

  • 0

the exponentiation operator (**) has higher precedence than the addition operator (+) so this means A ** B+C is interpreted as (A ** B) + C because the exponentiation operation has priority over the addition operation

 

also worth noting that exponentiation has higher precedence than multiplication/division so a more complex formula like A + B * C ** D would be interpreted as A + (B * (C ** D)) so you have to manually reorder the operations with explicit parentheses if you want to change the precedence, like (A + (B * C)) ** D

Share this post


Link to post
Share on other sites
  • 0

the code is :

function	int__	{
	set .@num, atoi(""+getarg(0));
	if ( .@num == 0 || .@num >= 2147483647 ) return getarg(0);
	set .@l, getstrlen(""+.@num);
	for ( set .@i,0; .@i < .@l; set .@i, .@i + 1 ) {
		set .@num$, .@num % pow(10,.@i+1) / (10**.@i) + .@num$;
			if ( (.@i+1) % 3 == 0 && .@i+1 != .@l ) set .@num$, ","+ .@num$;
	}
	return .@num$;
}

i got this warning: 

[Warning]: script error in file 'npc/custom/meus/tzeny.txt' line 62 column 23
    This command is deprecated and it will be removed in a future update. Please see the script documentation for an alternative.

    59:         if ( .@num == 0 || .@num >= 2147483647 ) return getarg(0);
    60:         set .@l, getstrlen(""+.@num);
    61:         for ( set .@i,0; .@i < .@l; set .@i, .@i + 1 ) {
*   62:                 set .@num$, .@num % pow(10,.@i+1) / (10**.@i) + .@num$;
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    63:                         if ( (.@i+1) % 3 == 0 && .@i+1 != .@l ) set .@num$, ","+ .@num$;
    64:         }
    65:         return .@num$;

and in game  script ok.

 

ForSnsscreen005.jpg.706eaabfdbb24885a15a894897e4ee3f.jpg

when o remove POW and change to the new mode ( set .@num$, .@num % ((10**.@i)+1) / (10**.@i) + .@num$;)

i got this in NPC.

ForSnsscreen003.jpg.2b3bce5e163eabb1f27fab3c73c9aeaf.jpg

Share this post


Link to post
Share on other sites
  • 0

its work man, thank you!

but now i received warning.

[Warning]: script:op_2num: overflow detected op=C_POW i1=10 i2=10
[Debug]: Source (NPC): Mestre dos Ba�s at prontera (164,143)

 

Edited by brunosc

Share this post


Link to post
Share on other sites
  • 0

10 to the power of 10 is 10,000,000,000 but the scripting engine uses signed 32-bit integers and the maximum value that can be held by such integers is 2,147,483,647 (2^31 − 1).

Any value above this will cause the integer to overflow so you have to be aware of this and manually check the boundaries. In your case this would mean checking that getarg(0) is shorter than 10 characters long so

if ( .@num == 0 || .@num >= 10 ** 9 ) return getarg(0);

instead of

if ( .@num == 0 || .@num >= 2147483647 ) return getarg(0);

to avoid the case where getstrlen is above 10

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.