Jump to content
  • 0

Division problem


foxtux

Question


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  2
  • Reputation:   0
  • Joined:  10/06/12
  • Last Seen:  

I was trying to make a npc and had a problem when making a division ... count returns 0

prt_in,63,58,3 script test 826,{
set .price_R, 100000;
set .desc, 50;
mes "repair all?";
next;
if(select("- yes:- close")==1){
mes "ok";
set .price_R2, .price_R*(.desc/100);
set Zeny, Zeny - .price_R2;
atcommand "@repairall";
close;
}
else {close;}

}

.desc/100 >> Returns 0... how to solve this?

thks

Link to comment
Share on other sites

5 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1132
  • Joined:  05/27/12
  • Last Seen:  

Why parentheses? Scripts don't support decimals.

.price_R*.desc/100

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  2
  • Reputation:   0
  • Joined:  10/06/12
  • Last Seen:  

then it is impossible to discount percentages?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1132
  • Joined:  05/27/12
  • Last Seen:  

It is, so long as your result is greater than zero. You just need to be careful with your order of operations, making sure no result ever hits 0 or an unwanted decimal.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

So rA script language doesn't have any round/floor/ceiling function?

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10018
  • Reputation:   2369
  • Joined:  10/28/11
  • Last Seen:  

So rA script language doesn't have any round/floor/ceiling function?

there is.....

For Example :

5 / 2 = 2

the actual result should be 2.5 but it only return 2 ....

decimal is not supported in emulator...


in your case....

.price_R*(.desc/100);

this calculation .... is the problem...

( .desc/100 ) 

because emulator doesnt support decimal places....

if any possibility that your variable is below 100 ...it will return 0 ....

then...the calculation will become something like this..

.price_R * 0;

this is commen sense...every value that is multiply by 0 will return you 0 as answer....

basically it's the way how you write the formulae affect the answer it return .....


if you are doing it like this..

( .price_R * .desc ) / 100;

then it should be no problem...if your formulae...

( .price_R * .desc )

return a value bigger than 100 ....

  • Upvote 1
Link to comment
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.   Paste as plain text instead

  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.

×
×
  • Create New...