Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Rocco on Thu 18/03/2010 17:26:08

Title: math problem
Post by: Rocco on Thu 18/03/2010 17:26:08
i have this code
  index_pic = (sprite_ammount * (-currentPosition));
but get not the result i expected.

example
index_pic = 10 * (-7);
if i type this in my calculator i get = 3
if this code is executed in AGS i get = -30

how must this statement look like, to get the result i need?
Title: Re: math problem
Post by: NsMn on Thu 18/03/2010 17:36:20
Uhmm.... I'm seriously confused. Shouldn't it be -70?
Title: Re: math problem
Post by: Crimson Wizard on Thu 18/03/2010 18:05:08
Are you sure you dont type in "10 + (-7)" on your calculator?  :)
I don't have a clue about what may be wrong with AGS , however. Because, as NsMn said, it must be -70.

Title: Re: math problem
Post by: Calin Leafshade on Thu 18/03/2010 18:13:47
i dunno if -variablename works.

you might want to try -1 * variablename
Title: Re: math problem
Post by: Crimson Wizard on Thu 18/03/2010 18:30:08
Quote from: Calin Leafshade on Thu 18/03/2010 18:13:47
i dunno if -variablename works.
It must... I think I've used that couple of times.
Title: Re: math problem
Post by: CShelton on Thu 18/03/2010 18:39:29
Minus variable name does work but it gets weird with the order of operations when a multiply comes just before it.


variable1 * -variable2


Will totally flake out, so do this instead:


-variable2 * variable1


Oops, or just read Calin's reply that I somehow missed.
Title: Re: math problem
Post by: Rocco on Thu 18/03/2010 18:47:11
thx, it works now.  :)