• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Trigger Causes Instant Crash - Where's the Problem?

Status
Not open for further replies.
Level 6
Joined
Aug 12, 2007
Messages
201
  • ChekReplace
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Item-type of (Item being manipulated)) Equal to Iron Mace
        • Then - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Hero manipulating item) is selected by (Picked player)) Equal to True
                • Then - Actions
                  • Unit Group - Add (Hero manipulating item) to ClickedWhenItemSpeed
                  • Set TempPickedPlayer2 = (Picked player)
                • Else - Actions
          • Set HeroStrength = (Strength of (Triggering unit) (Exclude bonuses))
          • Set HeroAgility = (Agility of (Triggering unit) (Exclude bonuses))
          • Set HeroInteligence = (Intelligence of (Triggering unit) (Exclude bonuses))
          • Unit - Replace (Hero manipulating item) with a General (Slow Attack Speed) using The old unit's relative life and mana
          • Hero - Modify Strength of (Last replaced unit): Set to HeroStrength
          • Hero - Modify Agility of (Last replaced unit): Set to HeroAgility
          • Hero - Modify Intelligence of (Last replaced unit): Set to HeroInteligence
          • Unit - Set (Last replaced unit) movement speed to MoveSpeedBonus[(Player number of (Owner of (Triggering unit)))]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in ClickedWhenItemSpeed) Greater than or equal to 1
            • Then - Actions
              • Unit Group - Pick every unit in ClickedWhenItemSpeed and do (Actions)
                • Loop - Actions
                  • Selection - Add (Picked unit) to selection for TempPickedPlayer2
            • Else - Actions
              • Do nothing
        • Else - Actions
The second I try to pick up the Iron Mace item, the game bombs out. Can anyone tell me what might be causing it in here?
 
Level 6
Joined
Aug 12, 2007
Messages
201
Never ends? There's only 12 players to pick from. Also I tried running the map with that part disabled, it still conked out.

EDIT: Think I solved it, adding a second item to the OR made it not crash. I guess it was because it was looking for a second thing I just hadn't gotten around to adding yet.

EDIT EDIT: Nope I was wrong, for some reason it broke again, even though nothing changed from the last time I ran it.
 
Level 6
Joined
Aug 12, 2007
Messages
201
ya nvm what i said i thought it was a while loop, i have no idea whats wrong lol maybe the MoveSpeedBonus[] array is null when you set the movement speed?

Not as far as I can tell it isn't, but I'll test it by putting a number in there like 5 or something in place of variable.

EDIT: Still bombs when it is setting movement speed to 300 instead of MoveSpeedBonus

  • ChekReplace Copy
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Item-type of (Item being manipulated)) Equal to Iron Mace
              • (Item-type of (Item being manipulated)) Equal to Blue Herring
        • Then - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Triggering unit) is selected by (Picked player)) Equal to True
                • Then - Actions
                  • Unit Group - Add (Triggering unit) to ClickedWhenItemSpeed
                  • Set TempPickedPlayer2 = (Picked player)
                • Else - Actions
          • Set HeroStrength = (Strength of (Triggering unit) (Exclude bonuses))
          • Set HeroAgility = (Agility of (Triggering unit) (Exclude bonuses))
          • Set HeroInteligence = (Intelligence of (Triggering unit) (Exclude bonuses))
          • Unit - Replace (Hero manipulating item) with a General (Slow Attack Speed) using The old unit's relative life and mana
          • Hero - Modify Strength of (Last replaced unit): Set to HeroStrength
          • Hero - Modify Agility of (Last replaced unit): Set to HeroAgility
          • Hero - Modify Intelligence of (Last replaced unit): Set to HeroInteligence
          • Unit - Set (Last replaced unit) movement speed to 300.00
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in ClickedWhenItemSpeed) Greater than or equal to 1
            • Then - Actions
              • Unit Group - Pick every unit in ClickedWhenItemSpeed and do (Actions)
                • Loop - Actions
                  • Selection - Add (Picked unit) to selection for TempPickedPlayer2
            • Else - Actions
              • Do nothing
        • Else - Actions
This is what I am using now, still crashes. Maybe it's interacting with another trigger in some way? I'm pretty sure all those variables are only in use here though.

EDIT EDIT ETC:

  • ChekReplace Copy
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Iron Mace
          • (Item-type of (Item being manipulated)) Equal to Blue Herring
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Hero manipulating item) is selected by (Owner of (Triggering unit))) Equal to True
        • Then - Actions
          • Set ClickedWhenItemSpeed = True
        • Else - Actions
      • Set HeroStrength = (Strength of (Triggering unit) (Exclude bonuses))
      • Set HeroAgility = (Agility of (Triggering unit) (Exclude bonuses))
      • Set HeroInteligence = (Intelligence of (Triggering unit) (Exclude bonuses))
      • Unit - Replace (Hero manipulating item) with a General (Slow Attack Speed) using The old unit's relative life and mana
      • Hero - Modify Strength of (Last replaced unit): Set to HeroStrength
      • Hero - Modify Agility of (Last replaced unit): Set to HeroAgility
      • Hero - Modify Intelligence of (Last replaced unit): Set to HeroInteligence
      • Unit - Set (Last replaced unit) movement speed to 300.00
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ClickedWhenItemSpeed Equal to True
        • Then - Actions
          • Selection - Add (Last replaced unit) to selection for (Owner of (Last replaced unit))
        • Else - Actions
          • Do nothing
Ultra simplified it now, kinda desperate to figure out what's wrong. It just keeps crashing every single time.
 
Last edited:
Level 16
Joined
Oct 12, 2008
Messages
1,570
Is there any trigger that could make an infinite loop with selection event maybe? Only thing i could think of that makes it crash,,

And i think the thing Ghostwolf mentioned might be right, but i dont think it could make it crash, since you would just set a [jasslanguage]null[/jasslanguage] unit,,

EDIT: ReplaceUnitBJ(), the function GUI uses,, which shows Ghostwolf is probably wrong,,
JASS:
function ReplaceUnitBJ takes unit whichUnit, integer newUnitId, integer unitStateMethod returns unit
    local unit    oldUnit = whichUnit
    local unit    newUnit
    local boolean wasHidden
    local integer index
    local item    indexItem
    local real    oldRatio
    // If we have bogus data, don't attempt the replace.
    if (oldUnit == null) then
        set bj_lastReplacedUnit = oldUnit
        return oldUnit
    endif
    // Hide the original unit.
    set wasHidden = IsUnitHidden(oldUnit)
    call ShowUnit(oldUnit, false)
    // Create the replacement unit.
    if (newUnitId == 'ugol') then
        set newUnit = CreateBlightedGoldmine(GetOwningPlayer(oldUnit), GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    else
        set newUnit = CreateUnit(GetOwningPlayer(oldUnit), newUnitId, GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    endif
    // Set the unit's life and mana according to the requested method.
    if (unitStateMethod == bj_UNIT_STATE_METHOD_RELATIVE) then
        // Set the replacement's current/max life ratio to that of the old unit.
        // If both units have mana, do the same for mana.
        if (GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_LIFE) / GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE)
            call SetUnitState(newUnit, UNIT_STATE_LIFE, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        endif
        if (GetUnitState(oldUnit, UNIT_STATE_MAX_MANA) > 0) and (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_MANA) / GetUnitState(oldUnit, UNIT_STATE_MAX_MANA)
            call SetUnitState(newUnit, UNIT_STATE_MANA, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_ABSOLUTE) then
        // Set the replacement's current life to that of the old unit.
        // If the new unit has mana, do the same for mana.
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(oldUnit, UNIT_STATE_LIFE))
        if (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(oldUnit, UNIT_STATE_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_DEFAULTS) then
        // The newly created unit should already have default life and mana.
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_MAXIMUM) then
        // Use max life and mana.
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
    else
        // Unrecognized unit state method - ignore the request.
    endif
    // Mirror properties of the old unit onto the new unit.
    //call PauseUnit(newUnit, IsUnitPaused(oldUnit))
    call SetResourceAmount(newUnit, GetResourceAmount(oldUnit))
    // If both the old and new units are heroes, handle their hero info.
    if (IsUnitType(oldUnit, UNIT_TYPE_HERO) and IsUnitType(newUnit, UNIT_TYPE_HERO)) then
        call SetHeroXP(newUnit, GetHeroXP(oldUnit), false)
        set index = 0
        loop
            set indexItem = UnitItemInSlot(oldUnit, index)
            if (indexItem != null) then
                call UnitRemoveItem(oldUnit, indexItem)
                call UnitAddItem(newUnit, indexItem)
            endif
            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY
        endloop
    endif
    // Remove or kill the original unit.  It is sometimes unsafe to remove
    // hidden units, so kill the original unit if it was previously hidden.
    if wasHidden then
        call KillUnit(oldUnit)
        call RemoveUnit(oldUnit)
    else
        call RemoveUnit(oldUnit)
    endif
    set bj_lastReplacedUnit = newUnit
    return newUnit
endfunction
 
Level 6
Joined
Aug 12, 2007
Messages
201
Alright, I just woke up, time to address all these and try them out. Going to to do a bunch of edits here as I work through it.

Frist @bigapple90: Ill be reducing it as go here.

@Anachron: I don't understand why there is a do nothing function in the first place, it's kinda habit to put them in, Should I be deleting them all from my triggers after this?

@Maker: Replacing it with a footman now, back in a second.
EDIT: Interesting result, it didn't crash but it did freeze for about half a second as he picked up the item before turning into a footman.

@GhostWolf + @Yixx: Even if it's probably not going to work, I'll try setting it to last created.
EDIT: Yep still crashed, and this is with the trigger set back to replace him with a General (Slow Speed)

@Yixx: I'm sorry but I don't know any JASS or how to work it at all, so I'm going to need your help with that long code there. Am I supposed to put all that in a variable or copy past it as custom code? I really don't know how to do Jass.
EDIT: In the mean time I'll start messing around with the unit replacement part and with looking as JASS tutorials.
 
Last edited:
Level 4
Joined
May 17, 2008
Messages
75
Perhaps replacing the unit technically gives the new unit the items, causing the trigger to set itself off infinitely. Try turning the trigger off before replacing the unit, then turning it on afterwards.
 
Level 3
Joined
Feb 13, 2008
Messages
65
I hope that you are aware that in this trigger, the Hero Manipulating Item and Triggering unit are the same unit.

Also, if you could explain what the goal of this trigger is then maybe some of us could help you rewrite it so it wont crash your game everytime it runs
 
Level 6
Joined
Aug 12, 2007
Messages
201
Perhaps replacing the unit technically gives the new unit the items, causing the trigger to set itself off infinitely. Try turning the trigger off before replacing the unit, then turning it on afterwards.

THIS COULD BE IT. It' sounds sound, I'll add a condition that says the Hero picking it up is just the regular General. Cross my fingers.
EDIT: That fixed it, no crash.

And to Tiaan, when the Hero gets a different item, I wanted to change his cooldown rate with attacks, but all the item speed changing abilities screwed up the animations. This way I am changing the Hero and retaining all his stats and things while swapping it for a unit that has a shorter/longer cooldown.
 
Try this:
  • Trigger
  • Events
    • Unit - A unit acquires an item
  • Conditions
    • ((Item-type) of (Item being manipulated)) Equal to Iron Mace
  • Actions
    • Set Point1 = (Position of (Triggering unit))
    • Set Owner = (Owner of (Triggering unit))
    • For each (Integer A) from 1 to 12, do (Actions)
      • Loop - Actions
        • If/ Then/ Else
          • If (Conditions)
            • (Triggering unit) is selected by Player(IntegerA) Equal to True
          • Then (Actions)
            • Unit Group - Add (Triggering unit) to ClickedWhenItemSpeed
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Number of units in ClickedWhenItemSpeed) Greater than 1
              • Then - Actions
                • Unit Group - Pick every unit in ClickedWhenItemSpeed and do (Actions)
                  • Loop - Actions
                    • Selection - Add (Picked unit) to selection for Player(IntegerA)
    • Set HeroStrength = (Strength of (Triggering unit) (Exclude bonuses))
    • Set HeroAgility = (Agility of (Triggering unit) (Exclude bonuses))
    • Set HeroInteligence = (Intelligence of (Triggering unit) (Exclude bonuses))
    • Unit - Remove (Triggering unit) from the game
    • Unit - Create 1 General (Slow Attack Speed) at Point1 for (Owner) facing default building degrees
    • Hero - Modify Strength of (Last created unit): Set to HeroStrength
    • Hero - Modify Agility of (Last created unit): Set to HeroAgility
    • Hero - Modify Intelligence of (Last created unit): Set to HeroInteligence
    • Unit - Set (Last created unit) movement speed to MoveSpeed
    • Custom script: call RemoveLocation (udg_Point1)
If this doesn't work, you will need a wait before you remove the unit. :/
 
Level 6
Joined
Aug 12, 2007
Messages
201
Try this:
  • Trigger
  • Events
    • Unit - A unit acquires an item
  • Conditions
    • ((Item-type) of (Item being manipulated)) Equal to Iron Mace
  • Actions
    • Set Point1 = (Position of (Triggering unit))
    • Set Owner = (Owner of (Triggering unit))
    • For each (Integer A) from 1 to 12, do (Actions)
      • Loop - Actions
        • If/ Then/ Else
          • If (Conditions)
            • (Triggering unit) is selected by Player(IntegerA) Equal to True
          • Then (Actions)
            • Unit Group - Add (Triggering unit) to ClickedWhenItemSpeed
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Number of units in ClickedWhenItemSpeed) Greater than 1
              • Then - Actions
                • Unit Group - Pick every unit in ClickedWhenItemSpeed and do (Actions)
                  • Loop - Actions
                    • Selection - Add (Picked unit) to selection for Player(IntegerA)
    • Set HeroStrength = (Strength of (Triggering unit) (Exclude bonuses))
    • Set HeroAgility = (Agility of (Triggering unit) (Exclude bonuses))
    • Set HeroInteligence = (Intelligence of (Triggering unit) (Exclude bonuses))
    • Unit - Remove (Triggering unit) from the game
    • Unit - Create 1 General (Slow Attack Speed) at Point1 for (Owner) facing default building degrees
    • Hero - Modify Strength of (Last created unit): Set to HeroStrength
    • Hero - Modify Agility of (Last created unit): Set to HeroAgility
    • Hero - Modify Intelligence of (Last created unit): Set to HeroInteligence
    • Unit - Set (Last created unit) movement speed to MoveSpeed
    • Custom script: call RemoveLocation (udg_Point1)
If this doesn't work, you will need a wait before you remove the unit. :/

It's been fixed, it was because when he replaces, the trigger fires over and over again. I'll look over yours though and see if I can optimize mine from anything in there though.
 
Status
Not open for further replies.
Top