math problem

Started by Rocco, Thu 18/03/2010 17:26:08

Previous topic - Next topic

Rocco

i have this code
Code: ags
  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?

NsMn

Uhmm.... I'm seriously confused. Shouldn't it be -70?

Crimson Wizard

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.


Calin Leafshade

i dunno if -variablename works.

you might want to try -1 * variablename

Crimson Wizard

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.

CShelton

Minus variable name does work but it gets weird with the order of operations when a multiply comes just before it.

Code: ags

variable1 * -variable2


Will totally flake out, so do this instead:

Code: ags

-variable2 * variable1


Oops, or just read Calin's reply that I somehow missed.

Rocco

thx, it works now.  :)

SMF spam blocked by CleanTalk