# [Solved]Bugged Maths

Status
Not open for further replies.

#### Freyky

Level 4
I've got a problem with an income trigger, it should work like this: Lumber Mill created > add +1 to interger variable, every X sec give added X to player X.

The creation/build works fine, but the remove when a unit of type Lumber Mill dies seems to be bugged.
The problem with the decrease now is.. Everytime I build 5x a lumber mill I get +5 income, 5 get destroyed but I get -6 income... repeats everytime 5 lumber mills are being destroyed.

• wood increase
• Events
• Unit - A unit Finishes construction
• Conditions
• Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of (Constructed structure)) Equal to Lumber Mill
• Then - Actions
• Set income_wood[(Player number of (Owner of (Constructed structure)))] = (income_wood[(Player number of (Owner of (Constructed structure)))] + 1)
• Else - Actions
• Do nothing
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of (Constructed structure)) Equal to Lumber Mill v2
• Then - Actions
• Set income_wood[(Player number of (Owner of (Constructed structure)))] = (income_wood[(Player number of (Owner of (Constructed structure)))] + 5)
• Else - Actions
• Do nothing
Bugged function:
• wood decrease
• Events
• Unit - A unit Dies
• Conditions
• Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• income_wood[(Player number of (Owner of (Dying unit)))] Greater than 0
• (Unit-type of (Dying unit)) Equal to Lumber Mill
• Then - Actions
• Set income_wood[(Player number of (Owner of (Dying unit)))] = (income_wood[(Player number of (Owner of (Dying unit)))] - 1)
• Else - Actions
• Do nothing
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• income_wood[(Player number of (Owner of (Dying unit)))] Greater than 0
• (Unit-type of (Dying unit)) Equal to Lumber Mill
• Then - Actions
• Set income_wood[(Player number of (Owner of (Dying unit)))] = (income_wood[(Player number of (Owner of (Dying unit)))] - 5)
• Else - Actions
• Do nothing
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• income_wood[(Player number of (Owner of (Dying unit)))] Less than 0
• Then - Actions
• Set income_wood[(Player number of (Owner of (Dying unit)))] = 0
• Else - Actions

Level 8
You're checking the same unit-type in the second If-Then-Else statement of your Wood Decrease trigger; it should be Lumber Mill v2 instead. You can also remove all the DoNothing actions, they're worse than just leaving the Else sections blank.

#### Freyky

Level 4
I know that it isn't the issue because I've added that function like 2mins before I posted. It has bugged before already

Level 8
Alright. Well there doesn't seem to be anything else in these triggers that would cause the problem you described.

What happens to your income when they each get destroyed? Do you still lose 1 income per mill as expected? What happens when you have any other number of mills or does this only happen when you have five destroyed?

#### Dr Super Good

Spell Reviewer
Level 64
I know that it isn't the issue because I've added that function like 2mins before I posted. It has bugged before already
Please post your bugged triggers that you tested and can confirm are bugged. Preferably post the map as well.

#### Freyky

Level 4
I don't know how, but it seems like it's fixed now, I had the same problem on another map..

Works perfect now, 1 mill created = +1, 1 mill destroyed = -1

#### Wietlol

Level 24
Also check if destroying an unfinished lumber mill will bug the resource income.

#### Freyky

Level 4
Tbh it does, I figured that out later yesterday.

I've been building 5 lumbermills, 2 were finished, 3 canceled and after that I got 0 lumber per sec, which should be 2 at least.

• wood increase
• Events
• Unit - A unit Finishes construction
• Conditions
• Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of (Constructed structure)) Equal to Lumber Mill
• Then - Actions
• Set income_wood[(Player number of (Owner of (Constructed structure)))] = (income_wood[(Player number of (Owner of (Constructed structure)))] + 2)
• Else - Actions
• Do nothing
• wood decrease
• Events
• Unit - A unit Dies
• Conditions
• Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• income_wood[(Player number of (Owner of (Dying unit)))] Greater than 0
• (Unit-type of (Dying unit)) Equal to Lumber Mill
• Then - Actions
• Set income_wood[(Player number of (Owner of (Dying unit)))] = (income_wood[(Player number of (Owner of (Dying unit)))] - 2)
• Else - Actions
• Do nothing
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• income_wood[(Player number of (Owner of (Dying unit)))] Greater than 0
• (Unit-type of (Dying unit)) Equal to Lumber Mill v2
• Then - Actions
• Set income_wood[(Player number of (Owner of (Dying unit)))] = (income_wood[(Player number of (Owner of (Dying unit)))] - 8)
• Else - Actions
• Do nothing

Last edited:

#### Dr Super Good

Spell Reviewer
Level 64
You will need to add checks to your decrease trigger to catch incomplete buildings and not decrement the income.

#### Wietlol

Level 24
Just use a unit indexer and set a boolean to true for the buildings that were finished.
Check if that boolean is true for the dying unit.

#### Freyky

Level 4
And how do I do that ? I know how to make a boolean variable but Idk how to attach the variable to an unit.

#### Wietlol

Level 24
A unit indexer like this one gives every unit a unique number and stores that on the custom value of the unit.
This value can be loaded by triggers and be used as index for array variables.

So you implement that system, you create a boolean array and you set the boolean to true with the index of the custom value of the unit/building.

#### Freyky

Level 4
Hmm I thought of doing the same, but not as good as the indexer from the dude ^^.
Smth like an integer variable which adds +1 each time a unit gets created and then set the value of the variable to last created unit.

Well thank you ^^

#### Dr Super Good

Spell Reviewer
Level 64
When you add income from a unit add the unit to a global unit group. When a unit dies only remove the income if the unit is in the global group. Remember to remove the unit from the global group after the test to prevent a leak.

#### Freyky

Level 4
ive tried that before already and it didnt end up good, Ill keep it like it is now, seems to work like that. Thank you anyways

#### Dr Super Good

Spell Reviewer
Level 64
Ill keep it like it is now, seems to work like that.
What is it like now?

#### Freyky

Level 4
It's the same as before just with the unit indexer and boolean false/true check

Status
Not open for further replies.

Replies
2
Views
696
Replies
3
Views
647
Replies
3
Views
631
Replies
5
Views
843
Replies
5
Views
1K