# Variables. The hero that we needed and deserved but we did not get

I’ve come here with a a very simple grief: why didn’t we get an actually working variables in DE? For example:

• I have a variable called a
• I wanna increase all militias attack by 2 * a
• I’d like to just use the function Change Object attack -> Add -> 2 * a and have the work done but I can’t do it. It’d would be super simple and intuitive.

The actual problem that brang me here is following:

tot_val is a total value of units killed by this player

i=1000;
if (tot_val >= i) {
gold_of_this_player += 250;
i += 1000;
}

This trigger would have looping set so for the entire game the player would get 250 gold every time he’d pass another 1000 of the killed units’ value. A very simple trigger, you’d say, should be doable in a minute. Well, it’s not, because I can’t compare tot_val with i, I can’t even save total_val to a variable so I could compare the new variable with i.

There’s only one function that includes variables and it’s called “Modify Resource By Variable” which is… odd. Just let us use the function “Modify Resource” with the possibility of writing the whole operation, for example “1000 + Variable0 - b12 * CRISTINE”. Otherwise you’ll have to make like 50 special functions similar to “Modify Resource By Variable”, for example “Modify Object Attack By Variable”, “Modify Object Speed By Variable” etc.

2 Likes

I know this is old but in case someone else comes across this post like I did I will explain my solution to using variables to set values.

In my scenario I wanted to use a variable as a value as well but quickly realized this is not possible.
And after creating manual triggers for each new value I grew tired of it and spent a lot of time coming up with the following solution.
With 3 variables and 3 triggers you can use a variable as a value. Seems like a lot, but this can replace an infinite amount of triggers

3 Variables:

``````Rate (The value we want to use)
RateRemaining (Used to reverse itself back into rate while doing our desired Effect)
RateIsDraining =  1 (1 for On 0 for Off)
``````

3 Triggers:

``````RateDrain (Looping)
While Rate >= 1
Rate -= 1
RateRemaining += 1
``````
``````RateDrainEnd
When Rate = 0
Deactivate Trigger RateDrain
Activate Trigger RateEffectDrain
Change Variables RateIsDraining = 0
``````
``````RateEffectDrain (Looping)
While RateRemaining >= 1
RateRemaining -= 1
Rate += 1
// Do something here i.e increase attack by 1
``````

Use some other triggers to increase or decrease rate to change the “amount” you want to increase attack by.

Activate RateDrain and RateDrainEnd when you want to do it again (Also don’t forget to set RateIsDraining to 1)
Use RateIsDraining to prevent a trigger from interfering with the loop if needed. (There was a bug in my game that was fixed by doing this)

The only problem is it can take time if you use really high numbers. Of course you can change the value 1 here by any number to fix this issue.
In my case the value can be anywhere from 1-100

Therefore I have created these set of triggers for draining by 1, 3 and 10. That way it always happens pretty quickly
Note: You only need one “RateDrainEnd” but it must deactivate/activate the triggers for 1, 3, 10.