Wait or Wait (Game-Time)?

jaybles169

New Member
Ran into an issue with this trigger and a couple other triggers that utilize a similar idea.

This is intended to be a heal over time potion, healing x amount each second for 5 seconds, but sometimes they bug out and don't stop after 5 seconds, thus repeatedly healing a character for an extended time but eventually stopping. I'm not sure if using Wait (Game-Time) would make a difference or not. Am I going about this the right way? If not, does anyone have suggestions for a different way to do it?

Trigger:
  • Rejuvenation Potions
    • Events
      • Unit - A unit Uses an item
    • Conditions
    • Actions
      • -------- Lesser Rejuv --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item being manipulated) Equal to (Item carried by (Triggering unit) of type Potion of Lesser Rejuvenation)
        • Then - Actions
          • For each (Integer A) from 1 to 5, do (Actions)
            • Loop - Actions
              • Wait 1.00 seconds
              • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 180.00)
              • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + 150.00)
        • Else - Actions
      • -------- Greater Rejuv --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item being manipulated) Equal to (Item carried by (Triggering unit) of type Potion of Greater Rejuvenation)
        • Then - Actions
          • For each (Integer A) from 1 to 5, do (Actions)
            • Loop - Actions
              • Wait 1.00 seconds
              • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 500.00)
              • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + 400.00)
        • Else - Actions
 

tommerbob

Minecraft. :D
Yes. Don't use waits, especially inside a loop. They can be very buggy. Instead, use two triggers. The first trigger is to run when the hero drinks the potion. The second trigger will be a periodic trigger that will do the actual healing.
 

tommerbob

Minecraft. :D
For your first trigger, you want to do something like this: (free hand)

Trigger:
  • Events
    • Unit - A unit uses an item
    • Conditions
      • Or - Conditions
        • Item-type of (item being manipulated) equal to (Potion of Lesser Rejuvenation)
        • Item-type of (item being manipulated) equal to (Potion of Greater Rejuvenation)
    • Actions
      • Set HealTarget = (Triggering unit)
      • Set HealDuration = 5
      • Set HealType = Item-type of (item being manipulated)
      • Trigger - Turn on Heal Potion


And now for the periodic trigger:

Trigger:
  • Events
    • Time - every 1 second of (game time)
    • Conditions
    • Actions
      • Set HealDuration = (HealDuration - 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • HealType Equal to Potion of Lesser Rejuvenation)
        • Then - Actions
          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 180.00)
          • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + 150.00)
        • Else - Actions
    • -------- Greater Rejuv --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • HealType Equal to Potion of Greater Rejuvenation
      • Then - Actions
        • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 500.00)
        • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + 400.00)
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • HealDuration Less Than or Equal to 0
      • Then - Actions
        • Trigger - Turn off (This trigger)


That should work. The only problem is its not MUI, meaning that more than 1 unit cannot run this trigger at the same time.
 

Bogrim

y hello thar
The reason for your trigger breaks is because the loop action uses a variable to keep track of the current loop number. The variable you use, "Integer A", is a global variable. When you run a loop with waits, and another loop uses the variable in the duration, the first loop will break because of the variable's altered data. Printing the variable's value as in-game text would give you a clear example of this:

Integer A = 1
Integer A = 2
Integer A = 3
Integer A = 4
Integer A = 2 -> the loop went haywire

I've written a tutorial on how to create MUI loops in GUI here. However, loops may not be the best approach for your spell effect. Instead, you should consider using a hashtable and a periodic time event, as it will allow you to create different healing values and durations for the units in the trigger.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Jesus4Lyf Jesus4Lyf:
    Hmm, how to summarize... Moved to the USA and got married. Became a professional software engineer and solution lead. Learning Godot for game dev. :)
  • jonas jonas:
    So you are pursuing game dev as a hobby? What industry is your dayjob in?
  • jonas jonas:
    FAANG?
  • Jesus4Lyf Jesus4Lyf:
    Not quite FAANG, less pay for a less hours/stress. Yeah, game dev as a hobby.
  • jonas jonas:
    makes sense. Do we have a hobby game dev subforum to showcase some work?
  • Blackveiled Blackveiled:
    Happy Thursday
    +1
  • The Helper The Helper:
    Happy Thursday!
  • The Helper The Helper:
    TGIF!
  • The Helper The Helper:
    hey tom_mai please do not archive anymore news
  • Ghan Ghan:
    AMD Ryzen 7000 next week :D
    +1
  • The Helper The Helper:
    noice!
  • tom_mai78101 tom_mai78101:
    "hey tom_mai please do not archive anymore news" ----> Got it. What should we do with the "News Archive" subforum?
  • The Helper The Helper:
    I think leave it for real old news that cannot be sorted the reason we had it in the first place was a server issue that we do not have anymore. I don't want to get rid of the archive just not put anything in it for now until we figure it out more
  • The Helper The Helper:
    The side chat has nothing on the discord. it is not possible but the biggest thing on my wish list right now is a sidechat channel on the disord that hooks up to this...
  • Ghan Ghan:
    I've been selected for the Diablo IV beta.
    +1
  • Ghan Ghan:
    Woo!
    +1
  • The Helper The Helper:
    that is so cool
  • V-SNES V-SNES:
    Eh just noticed the new discord section on the side. Looks great!
    +1
  • Blackveiled Blackveiled:
    :( feels bad I can't ever get selected for any beta I sign up for. It's annoying as heck.
    +1
  • The Helper The Helper:
    Hello mgarcia! Happy Monday everyone!
  • The Helper The Helper:
    Happy Tuesday! :)

    The Helper Discord

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top