• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Create effect array in Jass

Status
Not open for further replies.
Level 5
Joined
May 26, 2012
Messages
76
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:
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.
 
Level 5
Joined
May 26, 2012
Messages
76
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'.
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.
 
Level 10
Joined
Mar 26, 2017
Messages
376
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:
Level 5
Joined
May 26, 2012
Messages
76
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
 
Level 10
Joined
Mar 26, 2017
Messages
376
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:

Uncle

Warcraft Moderator
Level 74
Joined
Aug 10, 2018
Messages
7,961
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.
 

Attachments

  • Delayed Destroy Effect.w3m
    16.6 KB · Views: 25
Last edited:
Level 5
Joined
May 26, 2012
Messages
76
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.

Thank you it works.
Today I started experementing with Jass functioncs and you gave me an idea to try

Code:
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.
 
Level 10
Joined
Mar 26, 2017
Messages
376
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:
function DestroySpecialEffectAfter takes nothing returns nothing
    local effect sfx = bj_lastCreatedEffect
    call TriggerSleepAction(4.00)
    call DestroyEffect(sfx)
    set sfx = null
endfunction
 

Uncle

Warcraft Moderator
Level 74
Joined
Aug 10, 2018
Messages
7,961
Also make sure to use fTime as the wait duration
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:
Status
Not open for further replies.
Top