1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Create effect array in Jass

Discussion in 'Triggers & Scripts' started by praudmur, Jun 6, 2020.

  1. praudmur

    praudmur

    Joined:
    May 26, 2012
    Messages:
    73
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Hello!
    My goal is to create an array of Special effects(In editor I cannot set the size of array so I have to create each level by script).


    upload_2020-6-6_23-21-27.png

    Code (Text):

    set udg_ff_SpecialEffectArrayTemp[0] = ?
    set udg_ff_SpecialEffectArrayTemp[1] = ?
    set udg_ff_SpecialEffectArrayTemp[2] = ?
    set udg_ff_SpecialEffectArrayTemp[3] = ?
    set udg_ff_SpecialEffectArrayTemp[4] = ?
    set udg_ff_SpecialEffectArrayTemp[5] = ?
     
    I don't undersrand what I should write instead of "?". And I can't seem to find full list of Jass functions anywhere on the internet. I would appreciate help.
     
  2. pr114

    pr114

    Joined:
    Mar 26, 2017
    Messages:
    173
    Resources:
    0
    Resources:
    0
    Size refers to the amount of array elements that are set to the Initial Value at map initialization.
    It is not needed and you can use the GUI for 'Set Variable'.
     
  3. praudmur

    praudmur

    Joined:
    May 26, 2012
    Messages:
    73
    Resources:
    1
    Maps:
    1
    Resources:
    1
    If I set variable via GUI it doesn't seem to work. I had the same issue with unit group array - they needed to be initialized with Create group function first before setting variable.
     
  4. pr114

    pr114

    Joined:
    Mar 26, 2017
    Messages:
    173
    Resources:
    0
    Resources:
    0
    Oops, misread the post and thought you were interested in sound variables.

    I reckon you intend to use 'Create a special effect'? This function does not take an effect argument, but rather returns an effect.

    You need a string variable for your purpose and put in model paths like "Abilities\Spells\Human\Banish\BanishTarget.mdl".
    Model paths can be found under Art in Abilities and Buffs/Effects.
     
    Last edited: Jun 6, 2020
  5. praudmur

    praudmur

    Joined:
    May 26, 2012
    Messages:
    73
    Resources:
    1
    Maps:
    1
    Resources:
    1
    I'm posting the code because I don't know if I explained it correctly.
    I have a group of units and I want to spawn an effect at each of them for 4 seconds and then remove it.

    upload_2020-6-7_5-46-13.png

    ff_SpecialEffectArrayTemp
    is a Special effect - array.

    ff_SpecialEffectArrayCount
    is a Integer.
    So this code doesn't work I think because special effect array is not initialized. I don't know how can I initialize it.



    Earlier I wrote about the same issue with unit group array. I managed to populate unit group arays with this code. I'm looking for the same solution here but I don't know how can I initialize a special effect array.

    Without the code highlighted in red - units would not be added to unit group array(realized it by trial and error)

    upload_2020-6-7_5-51-2.png

    upload_2020-6-7_5-54-47.png
     
  6. pr114

    pr114

    Joined:
    Mar 26, 2017
    Messages:
    173
    Resources:
    0
    Resources:
    0
    It works fine, you can test this:

    • Special Effect - Create a special effect attached to the overhead of Paladin 0000 <gen> using Abilities\Spells\Human\MassTeleport\MassTeleportTo.mdl
    • Set VariableSet effect[2] = (Last created special effect)
    • Special Effect - Destroy effect[2]



    As for Unit Group, the "Unit Group - Add" requires a unit group to add the unit to. This can be done like you did, or by using Initial Value Empty Unit Group, and then setting the size accordingly. For indexes 1 to size, it will automatically create an empty unit group and bind it to that array index.

    But for instance "Unit Group - Pick every unit" requires no such initalization as the function creates an empty unit group and then adds the appropriate units to it. If you had previously assigned another unit group to that variable it will remain in memory but become unreachable.
     
    Last edited: Jun 7, 2020
  7. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,272
    Resources:
    0
    Resources:
    0
    You can use this "system" to create and destroy an effect after a delay. It saves your last created special effect as a local variable, and after Delayed_Duration (a time you set) it will destroy the special effect.
    • Delayed Destroy Effect
      • Events
      • Conditions
      • Actions
        • Custom script: local effect sfx = GetLastCreatedEffectBJ()
        • Wait Delayed_Duration seconds
        • Custom script: call DestroyEffect(sfx)
        • Custom script: set sfx = null


    Here's an example of using it:
    • Example DDE
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
      • Actions
        • Special Effect - Create a special effect attached to the chest of (Triggering unit) using Abilities\Spells\Human\DivineShield\DivineShieldTarget.mdl
        • Set VariableSet Delayed_Duration = 1.00
        • Trigger - Run Delayed Destroy Effect <gen> (ignoring conditions)


    Some other things:
    You don't need to initialize the Unit Groups with CreateGroup(), simply set the Variables Size in the Variable Editor (it won't work if you try to adjust the Size outside of it) to a large enough number.

    I think there's some Array issues introduced in the latest patches, but i'm not sure though. It feels like more and more variable types need their Size adjusted or they won't work properly.

    Also, looking at the one picture you posted with the 4 For Each (Integer A) Loops, you could simplify it to this instead:
    • Actions
      • For each (Integer A) from 1 to 4, do (Actions)
        • Loop - Actions
          • For each (Integer B) from 0 to 3, do (Actions)
            • Loop - Actions
              • Unit - Create 1 Footman for Player 1 (Red) at Point[(Integer B)] facing Default building facing degrees
              • Unit Group - Add (Last created unit) to UnitGroup[(Integer B)]

    It's recommended to use unique Integer variables instead of Integer A and Integer B.

    And you're leaking a Point when using "facing (Position of char_CrystalRef)" as it creates a Point at the position of this unit.
     

    Attached Files:

    Last edited: Jun 7, 2020
  8. praudmur

    praudmur

    Joined:
    May 26, 2012
    Messages:
    73
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Thank you it works.
    Today I started experementing with Jass functioncs and you gave me an idea to try

    Code (Text):
    function DestroySpecialEffectAfter takes real fTime returns nothing
        local effect sfx = GetLastCreatedEffectBJ()
        call TriggerSleepAction(4.00)
        call DestroyEffectBJ(sfx)
    endfunction
    However it didn't work from the loop. So I suppose function and triggers behave differently from the loop? I thought that custom script was supposed to work the same as the trigger.
     
  9. pr114

    pr114

    Joined:
    Mar 26, 2017
    Messages:
    173
    Resources:
    0
    Resources:
    0
    A trigger is a game engine object and must be called with TriggerExecute.
    A function can be called with call <funcname>(arguments)

    A few small changes for your function:
    Code (Text):
    function DestroySpecialEffectAfter takes nothing returns nothing
        local effect sfx = bj_lastCreatedEffect
        call TriggerSleepAction(4.00)
        call DestroyEffect(sfx)
        set sfx = null
    endfunction
     
  10. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,272
    Resources:
    0
    Resources:
    0
    Also make sure to use fTime as the wait duration
    Code (vJASS):

    function DestroySpecialEffectAfter takes real fTime returns nothing
        local effect sfx = bj_lastCreatedEffect
        call TriggerSleepAction(fTime)
        call DestroyEffect(sfx)
        set sfx = null
    endfunction
     
    You'd call it like this:
    • Custom script: call DestroySpecialEffectAfter(4.00)
     
    Last edited: Jun 7, 2020