Simple Mathemetical Scripting Problem

Des80

Member
int buypotions = my_adventures() - have_effect(to_effect(176));
int potionfinally = buypotions / 10;

Does Mafia not give you decimal points in strings and ignores everything past the decimal ? Is it possible to use int round( float ) to make it go to the next higher up if its at a .1 or .2 and if so how would I plug that into a Variable ? Would Changing it to float instead of int help since that does Give you decimal Points it would seem. I have also tried the in ceil(float) and it wont give me the next value up when I know it should be 3.7 it should show 4 right since thats the next highest integer but it gives me 3.

Maybe I should explain what Im trying to do. I want to take the amount of Effect I have from the amount of Adventures I have left then I want to divide that by how many each of the buff gives ( 10 or 20 or 30 etc etc ) and if I get a whole number I would like to buy that many Potions so I dont have to do a while statement and buy 1 potion at a time and if I get a Decimal number I want it to buy 1 more potion that way it will have that effect so say that potionfinally brings me the number 30 and the buff does 10 each I want it to buy 3 of the potions and use them but if it has 3.1 or anything with a decimal point I want it to buy 4 of the potions and use them. I hope this makes sense.
 
Last edited:

Bale

Minion
In java, an integer divided by an integer is always rounded down. The way to fix that is by making one of those numbers a float:

Code:
int buypotions = my_adventures() - have_effect(to_effect(176));
int potionfinally = ceil(buypotions / 10.0);

Edit: ninja'ed by Veracity. Her solution is clever and amusing. I like it.
 

Des80

Member
and would you do 19 for if you are doing /20 and 29 for if you are doing /30 ?

Also Bale I did change them into float and forgot to edit that sorry.

You guys have been great help with all of the questions I've been asking.
 

Des80

Member
here is what I had tried
float buypotions = my_adventures() - have_effect(to_effect(176));
float potionfinally = buypotions / 10;
int shouldwork = ceil(potionfinally);
but that still gave me the lower integer but you are saying to have in the division so thanks Let me try that really fast thanks a lot.
Ok I plugged it in Im just using my adventures which I have 37 after nightcap and that should show 3.7

float mathtime = ceil(my_adventures()) /10.0;
shows me 3.7 instead of the 4 Im trying to get
when I try it as an int mathtime it shows me 3
 
Last edited:

Bale

Minion
float mathtime = ceil(my_adventures()) /10.0;
shows me 3.7 instead of the 4 Im trying to get

Oh god, no. Please re-read my first reply. (Your parenthesis are messed up.)

Code:
float mathtime = ceil(my_adventures() /10.0);
 

Des80

Member
Yeah I noticed that Bale when I was redoing it it was my mistake but I had already gotten it to work a different way.
That should allow me to incorporate that into the buffing Part of the Script Im writing and not have to go through 40+ potions 1 at a time until my effect equals the amount of adventures I have thank you.
Code:
float adventure = my_adventures() /10.0;
int mathtime = ceil(adventure);
 

Darzil

Developer
The reason Veracity suggested using Ints that was I think that computers can get quite funky with floats sometimes. They can drop tiny fractions off numbers which can make rounding down give unexpected answers. Sometimes you have no choice, but as you are dealing with discrete units (adventures) here it may be good to use int.
 

xKiv

Active member
# only works correctly if turns_needed is at least 1 (int arithmetic is truncated towards zero, so 1+(0-1)/duration=1 for any duration greater than 1):
int amount_to_buy = 1 + ( turns_needed - 1 ) / duration_per_potion;
 
Top