1. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  2. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  3. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Simple trigger doesn't work!

Discussion in 'Triggers & Scripts' started by vlekje5, Feb 2, 2020.

  1. vlekje5

    vlekje5

    Joined:
    Dec 1, 2010
    Messages:
    255
    Resources:
    0
    Resources:
    0
    I really didn't know how to describe this with a fitting title.

    Anyway, I want the mana cost of an ability to be equal to the players current mana. I want it to update periodically aswell.
    I came to the solution below. However this is the first time i use unit groups, and the "set mana cost of ability" action. The trigger doesn't seem to be working and i can't wrap my head around why.

    Does anyone have any idea what i'm doing wrong?

    • Untitled Trigger 014
      • Events
        • Time - Every 1.00 seconds of game time
      • Conditions
      • Actions
        • Unit Group - Pick every unit in (Units owned by Player 1 (Red) of type Magroth the Defender) and do (Actions)
          • Loop - Actions
            • Unit - For Unit (Picked unit), Set mana cost of ability War Stomp, Level: (Level of War Stomp for (Picked unit)) to (Integer((Mana of (Picked unit))))



    EDIT:
    Okay it seems like the value does change, but only when i level up the ability. I was expecing it to update based on the function not the leveling up. any suggestions for alternative methods of achieving this?
     
    Last edited: Feb 2, 2020
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    • I think it would be easier to just give the spell no mana cost and then just set total mana to 0 upon casting it. However, if you don't want to do that:

    • "Units owned by..." leaks a group (refer to my post in your other thread for how to clean leaks)
    • It would be best to create a group specifically for this spell and add units to the group when they learn the spell. Then pick units in that group periodically. Doing it this way does not leak the group since you constantly re-use it.
    • 1.00 is a slow refresh rate for something like this. You can safely get away with 0.25 or even less without having an impact on game execution in any way.
     
  3. Sabe

    Sabe

    Joined:
    Jul 30, 2018
    Messages:
    434
    Resources:
    1
    Spells:
    1
    Resources:
    1
    The problem is the 0-indexing. Level 0 on the trigger is actually level 1 on the ability in the game. So it should be ((Level of War Stomp for (Picked unit)) - 1).
     
  4. vlekje5

    vlekje5

    Joined:
    Dec 1, 2010
    Messages:
    255
    Resources:
    0
    Resources:
    0
    While i have considered that and it would be easier, i like the fact that the mana cost updates and is visible when you look at the spell. It adds a sense of immersion imo.

    i'm still having some troubles wrapping my head around what a leak is exactly, Can i see it in a way as the group geting re created every time the timer runs, eventually causing it to overload the memory with unused groups?

    What exactly is the impact leaks have on the game or the functioning of a trigger in very simple terms?

    Yeah, i just put it on something random while i tested stuff out.


    This seems to have fixed the problems i had with the function not running as intended. the mana is updating apropiately now.
     
  5. Sabe

    Sabe

    Joined:
    Jul 30, 2018
    Messages:
    434
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Leak is a lost piece of information that keeps taking up the CPU's memory, but cannot be used or accessed in any way. The result is lag and in most severe cases it can cause crashes.

    Imagine it this way: you tell the game to create a unit to a location. A "point object" is then created at that location. Then the unit is created to the position of this point object. Now, if you created another unit again at some location, the first unit's spawn location would be lost. The point object that was created is still there, but now you have no way to access that, because you declared another point location, thus creating another point object. And because all those point objects still exist there, the computer has to keep them in its memory, even though you have no use for them, because you can't access them.

    Here are some good threads about how to clear these leaks:
    - Things That Leak
    - Memory Leaks
     
  6. vlekje5

    vlekje5

    Joined:
    Dec 1, 2010
    Messages:
    255
    Resources:
    0
    Resources:
    0


    Oh, I have seen the things that leak page before (thanks to pyrogasm!)

    But i think i understand now why it's important to avoid them!
    The concept was still pretty new to me since i've first head about them yesterday xD
    Right now it seems pretty clear though.

    thanks