Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Thu 21/02/2019 08:18:16

Title: SOLVED: Scaling int to float
Post by: Slasher on Thu 21/02/2019 08:18:16
Hi

I have a  player which is a little to big for the scene so I manually scaled him down to scale with a boat.

However, the boat walks walkable scaling 70/50.

So I did this:

Code (ags) Select


function repeatedly_execute_always() {
cTurner.Scaling=cSpeedBoat.Scaling/2;
}
}


Is there a way to turn this into a float like /2.2?

Cheers ;)
Title: Re: Scaling int to float
Post by: Gilbert on Thu 21/02/2019 08:35:24
Since Character.Scaling is an int property, you cannot do floating point math directly.
But you can do either:
Code (ags) Select

function repeatedly_execute_always() {
cTurner.Scaling=(cSpeedBoat.Scaling*50)/70; //Remember the multiplication MUST be done before the division.
}

or alternatively:
Code (ags) Select

function repeatedly_execute_always() {
cTurner.Scaling=Maths.FloatToInt(Maths.IntToFloat(cSpeedBoat.Scaling)/1.4, eRoundNearest);
}

The results of the two methods should be more or less the same, save for some rounding differences.

(Note: This was written when your post wasn't edited yet, hence the 1.4 and not 2.2 .)
Title: SOLVED: Re: Scaling int to float
Post by: Slasher on Thu 21/02/2019 09:00:21
Thanks Gilbert  (nod)