Page 1 of 1

reversing variables

PostPosted: Thu Sep 04, 2008 9:17 am
by Kalladdolf
NOTE: WHO DOESN'T WANT TO READ ALL THIS TEXT CAN JUST LOOK AT THE DEMO I POSTED!

This is actually so simple it doesn't even deserve to be posted in the advanced section.
But as my experience proved there has been a lot of confusion about that matter these days.

What someone wants to do:
He has one var which is hundred.
He has another var which is something between hundred and zero.
still with me?
He has a scale from zero to hundred and another variable which he can place anywhere between zero and hundred as he likes:

0.......................var1...............100
0..........var1............................100
0.............................var1.........100

And that isn't very hard to make.

Now here's the problem:
He has another variable, let's call it var2.

he wants var2 to have exactly the opposite value to var1.

like this:

0..........var1............................100
0............................var2..........100

or like this:

0.var1.....................................100
0.....................................var2.100

or like this:

0..................var1....................100
0..................var2....................100


the formula is (big deal X_X):

Code: Select all
var2 = var1*(-1)+100; // hundred can be replaced with a variable depending whether you also wanna change it.


For those guys who are better at learning by seeing:
here's a small demo:
r_vars.zip
O_O
(742.4 KiB) Downloaded 141 times


the question is:
what is this good for?

- if you made a health bar and saved the frames in the wrong order
- enemy avoiding techniques
- and much more

I betcha most of you knew this before... but anyway... here goes :D

Re: reversing variables

PostPosted: Thu Sep 04, 2008 11:11 am
by Azou
It's usefull!Thanx,Kall!! :D

Re: reversing variables

PostPosted: Sun Sep 07, 2008 2:15 pm
by DilloDude
Or just simply
Code: Select all
var2 = 100 - var1;

Re: reversing variables

PostPosted: Sun Sep 07, 2008 3:32 pm
by Kalladdolf
thanks, that makes it less complicated :D