• 🏆 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] Categorizing Unit-Types Using Variables?

Status
Not open for further replies.
Level 5
Joined
Nov 6, 2014
Messages
70
I have a set of 6 'arakkaoa' units and I want to make a unit type of it.
So I made a unit type variable called "RaceArakkoa" then all the index is 0 to 6.

Then my problem is that I have made an ability like "Ancient Spirit"

I made a trigger when unit dies and conditioning that if the unit type of the dying unit is "RaceArakkoa", so it's too confusing what will I put in the [index] part of it.

I don't think I should use "MAX" (0,6) because the unit revived might be confusing. Any ideas how can I categorize units and successfully input them in such abilities like that?

HERE IS THE SCREENIE

  • function Trig_RaceOgre_Copy_Actions takes nothing returns nothing
    • set udg_RaceOgre[0] = 'o008'
    • set udg_RaceOgre[1] = 'o00A'
    • set udg_RaceOgre[2] = 'o00D'
    • set udg_RaceOgre[3] = 'o00F'
    • set udg_RaceOgre[4] = 'n005'
    • set udg_RaceOgre[5] = 'n007'
    • set udg_RaceOgre[6] = 'n006'
  • endfunction
  • //===========================================================================
  • function InitTrig_RaceOgre_Copy takes nothing returns nothing
    • set gg_trg_RaceOgre_Copy = CreateTrigger( )
    • call TriggerRegisterTimerEventSingle( gg_trg_RaceOgre_Copy, 2.00 )
    • call TriggerAddAction( gg_trg_RaceOgre_Copy, function Trig_RaceOgre_Copy_Actions )
  • endfunction
then another trigger is
  • function Trig_A_Ogre_Rising_Copy_Conditions takes nothing returns boolean
    • if ( not ( GetUnitTypeId(GetDyingUnit()) == udg_RaceOgre[IMaxBJ(0, 6)] ) ) then
      • return false
    • endif
    • return true
  • endfunction
  • function Trig_A_Ogre_Rising_Copy_Actions takes nothing returns nothing
  • endfunction
  • //===========================================================================
  • function InitTrig_A_Ogre_Rising_Copy takes nothing returns nothing
    • set gg_trg_A_Ogre_Rising_Copy = CreateTrigger( )
    • call TriggerRegisterAnyUnitEventBJ( gg_trg_A_Ogre_Rising_Copy, EVENT_PLAYER_UNIT_DEATH )
    • call TriggerAddCondition( gg_trg_A_Ogre_Rising_Copy, Condition( function Trig_A_Ogre_Rising_Copy_Conditions ) )
    • call TriggerAddAction( gg_trg_A_Ogre_Rising_Copy, function Trig_A_Ogre_Rising_Copy_Actions )
  • endfunction
 
Last edited:
Level 9
Joined
Apr 23, 2011
Messages
527
just remove the condition and when you are creating the unit, use (Unit type of (Dying unit)).

by the way, you should post your triggers so we can more clearly understand the problem. to know how, check this link.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,178
You should post JASS in JASS tags.

JASS:
udg_RaceOgre[IMaxBJ(0, 6)]
This makes no sense since JASS is not a functional language. What happens is IMaxBJ(0, 6) is evaluated and returns 6 ( 6 > 0) so it might as well be the following line.
JASS:
udg_RaceOgre[6]
Which is clearly not what you are after.

The first approach which does what you want inefficiently is to loop through all arrays.
JASS:
function Trig_A_Ogre_Rising_Copy_Conditions takes nothing returns boolean
    local integer i = 7 // number of elements in array
    local integer utype = GetUnitTypeId(GetDyingUnit())
    loop
        set i = i - 1
        if utype == udg_RaceOgre[i] then
            return true
        endif
        exitwhen i <= 0
    endloop
    return false
endfunction

The other slightly more efficient approach is to use a hashtable. Since unit types are integers they can be used as one of the two hashes. Some value can then be assigned at the index (eg boolean true). This scales a lot better than the previous approach since it has a complexity as good as O(1) as opposed to O(n) for the solution above.

In that case the following functions would work with a GUI global hashtable called "OTHash".

JASS:
function Trig_RaceOgre_Copy_Actions takes nothing returns nothing
    local integer datakey = 0 // unique key for this data
    local integer i = 7 // number of elements in array
    // initialize array list
    set udg_RaceOgre[0] = 'o008'
    set udg_RaceOgre[1] = 'o00A'
    set udg_RaceOgre[2] = 'o00D'
    set udg_RaceOgre[3] = 'o00F'
    set udg_RaceOgre[4] = 'n005'
    set udg_RaceOgre[5] = 'n007'
    set udg_RaceOgre[6] = 'n006'
    // map data to types
    set udg_OTHash = InitHashtable() // might want this somewhere else
    loop
        set i = i - 1
        call SaveBoolean(udg_OTHash, udg_RaceOgre[i], datakey, true)
        exitwhen i <= 0
    endloop
endfunction

function Trig_A_Ogre_Rising_Copy_Conditions takes nothing returns boolean
    // Types that pass are set to true. Types that do not are not set.
    return HaveSavedBoolean(udg_OTHash, GetUnitTypeId(GetDyingUnit()), 0)
endfunction
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,178
how can i do it in GUI?
But you are using JASS as the triggers you posted were JASS. If you wanted GUI then why not post GUI triggers?

Short answer is it is not possible due to how limited GUI is. The hashtable usage is not possible because you cannot typecast types to GUI integers despite them being implemented as integers internally (you need custom script or pure JASS to do that as that removes that fake GUI limit).

The loop approach is possible but you need to do it in the action part of the trigger using flow control statements (for X from 0 to 6, if then else if) since GUI conditions are very limited. You also have to re-structure the loop so that it sets a boolean since you cannot return (that would exit the action function pre-maturely).
 
Status
Not open for further replies.
Top