Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Solved] Bugged Maths

Discussion in 'Triggers & Scripts' started by Freyky, Jun 26, 2016.

  1. Freyky

    Freyky

    Joined:
    Aug 6, 2014
    Messages:
    87
    Resources:
    0
    Resources:
    0
    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
     
  2. Dehua_Darbuya

    Dehua_Darbuya

    Joined:
    Jan 28, 2016
    Messages:
    483
    Resources:
    0
    Resources:
    0
    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.
     
  3. Freyky

    Freyky

    Joined:
    Aug 6, 2014
    Messages:
    87
    Resources:
    0
    Resources:
    0
    I know that it isn't the issue because I've added that function like 2mins before I posted. It has bugged before already
     
  4. Dehua_Darbuya

    Dehua_Darbuya

    Joined:
    Jan 28, 2016
    Messages:
    483
    Resources:
    0
    Resources:
    0
    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?
     
  5. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,124
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Please post your bugged triggers that you tested and can confirm are bugged. Preferably post the map as well.
     
  6. Freyky

    Freyky

    Joined:
    Aug 6, 2014
    Messages:
    87
    Resources:
    0
    Resources:
    0
    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
     
  7. Wietlol

    Wietlol

    Joined:
    Aug 1, 2013
    Messages:
    4,638
    Resources:
    3
    Spells:
    3
    Resources:
    3
    Also check if destroying an unfinished lumber mill will bug the resource income.
     
  8. Freyky

    Freyky

    Joined:
    Aug 6, 2014
    Messages:
    87
    Resources:
    0
    Resources:
    0
    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: Jun 28, 2016
  9. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,124
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    You will need to add checks to your decrease trigger to catch incomplete buildings and not decrement the income.
     
  10. Wietlol

    Wietlol

    Joined:
    Aug 1, 2013
    Messages:
    4,638
    Resources:
    3
    Spells:
    3
    Resources:
    3
    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.
     
  11. Freyky

    Freyky

    Joined:
    Aug 6, 2014
    Messages:
    87
    Resources:
    0
    Resources:
    0
    And how do I do that ? I know how to make a boolean variable but Idk how to attach the variable to an unit.
     
  12. Wietlol

    Wietlol

    Joined:
    Aug 1, 2013
    Messages:
    4,638
    Resources:
    3
    Spells:
    3
    Resources:
    3
    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.
     
  13. Freyky

    Freyky

    Joined:
    Aug 6, 2014
    Messages:
    87
    Resources:
    0
    Resources:
    0
    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 ^^
     
  14. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,124
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
     
  15. Freyky

    Freyky

    Joined:
    Aug 6, 2014
    Messages:
    87
    Resources:
    0
    Resources:
    0
    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
     
  16. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,124
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    What is it like now?
     
  17. Freyky

    Freyky

    Joined:
    Aug 6, 2014
    Messages:
    87
    Resources:
    0
    Resources:
    0
    It's the same as before just with the unit indexer and boolean false/true check