Topic was automatically imported from the old Question2Answer platform.
Asked By
RubRub
Ejemplo: quiero hacer algo como esto, Si la variable a aumenta, la variable b disminuya, It is that I will implement it in an attempt of a catapult system like plants vs zombies
Lets say you have a variable x and a variable z.
Lets also assume that in the staring state x=200 and z=300.
You take the sum of x and z which is 500 in this case.
If you increase variable x in your code you can make z decrease the same amount x increases by setting z = 500 - x. I don’t know which programming language you are using to help you futher but this should give a pretty good idea of what you should do.
I don’t understand spanish. but just from the title of this question : if You want to bind some behavior to change in one particular variable You can use setget keyword.
var _myvar : int setget onvarset
var anothervar : int
code below subtracts one from anothervariable whenever _myvar increases :
func onvarset(value) :
if value > _myvar :
anothervar -= 1
_myvar = value
Setters require some setup to use properly, read about in documentation before You paste this code