reversing variables
Posted: Thu Sep 04, 2008 9:17 am
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):
For those guys who are better at learning by seeing:
here's a small demo:
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
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:
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