maths

Modders can post their questions on scripting and more.

Moderators: Slitherine Core, BA Moderators

Post Reply
enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1855
Joined: Sun May 15, 2011 8:47 am

maths

Post by enric »

Which is the correct syntax for removing a 30% of a value:

damage *= 0,7; // don't work (the 0.7 is not accepted by BA)
damage = damage * 7 / 10 ; // don't work

damage = damage * 7;
damage = damage / 10; Then it works but should be a better way no?
pipfromslitherine
Site Admin
Site Admin
Posts: 9898
Joined: Wed Mar 23, 2005 10:35 pm

Re: maths

Post by pipfromslitherine »

The script doesn't deal with precedence in the same way as regular C. The second approach is the recommended solution.

Cheers

Pip
Amaris
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 929
Joined: Fri Jul 23, 2010 11:08 am
Location: France
Contact:

Re: maths

Post by Amaris »

:shock:

Why so complicated?

I think it works:
damage = damage % 70;

:wink:
“Take care, my friend; watch your six, and do one more roll… just for me.”
enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1855
Joined: Sun May 15, 2011 8:47 am

Re: maths

Post by enric »

Thank Amaris, this works in the way that BA accept it but, unfortunately the result is not the searched.

damage = damage * 7;
damage = damage / 10; Then it works but should be a better way no?

If damage value was initially 100, after calculations is 70.

in your example
damage = damage % 70;

gives as result 30.

if using:

damage = damage % 30;

the result is 10 ????
Amaris
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 929
Joined: Fri Jul 23, 2010 11:08 am
Location: France
Contact:

Re: maths

Post by Amaris »

Sorry I'm mistaken! :oops: I didn't have BA under hand when I wrote this stupidity thing. :roll:

The % operator is the remainder of the Euclidean division. :roll:

Therefore the solution:
damage = damage * 7;
damage = damage / 10;
is better...

edit: correction of a second very stupid thing... :oops:
“Take care, my friend; watch your six, and do one more roll… just for me.”
Post Reply

Return to “Battle Academy : Modders Corner ”