[vJass] Array

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Now that I had holiday, starts my learning again.

Please explain what does this do:
I don't see it anywhere in the documentation...
JASS:

integer I = 0
integer O array I


What does the array do?

Edit -
Ah! Sorry for the confusing... guys.. It is from this post:
JASS:

//===========================================================================
//  Demo spell for using PUI in combination with global arrays
//  to create counters that are attached to unit
//
//  Author: Cohadar
//  Date: 2008.03.08
//===========================================================================

scope FleshHeap

globals
    private constant integer AID_FLESH_HEAP = 'A001'
    private constant integer AID_STR_BONUS  = 'A002'
    
    private constant integer HERO_PERCENT = 30
    private constant integer UNIT_PERCENT = 3
endglobals

globals    
    // do NOT use this arrays directly, use below functions
    private unit array PUI_unit
    private integer array PUI_counter
endglobals

//===========================================================================
private function GetCount takes unit whichUnit returns integer
    local integer index = GetUnitIndex(whichUnit)
    if PUI_unit[index] != whichUnit then
        set PUI_unit[index] = whichUnit
        set PUI_counter[index] = 0
    endif
    return PUI_counter[index]
endfunction

//===========================================================================
private function AddCount takes unit whichUnit, integer count returns nothing
    local integer index = GetUnitIndex(whichUnit)
    if PUI_unit[index] != whichUnit then
        set PUI_unit[index] = whichUnit
        set PUI_counter[index] = count
    else
        set PUI_counter[index] = PUI_counter[index] + count
    endif
endfunction

//===========================================================================
private function SetCount takes unit whichUnit, integer count returns nothing
    local integer index = GetUnitIndex(whichUnit)
    set PUI_unit[index] = whichUnit
    set PUI_counter[index] = count
endfunction

//===========================================================================
private function Actions takes nothing returns nothing
    local unit pudge = GetKillingUnit()
    local integer level = GetUnitAbilityLevel(pudge, AID_FLESH_HEAP)
    
    if IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) then
        call AddCount(pudge, level*HERO_PERCENT)
    else
        call AddCount(pudge, level*UNIT_PERCENT)
    endif
    
    if GetCount(pudge) >= 100 then
        call SetCount(pudge, 0)
        debug call BJDebugMsg("|c0000FF00" + "strength increased")
        call IncUnitAbilityLevel(pudge, AID_STR_BONUS) // green stat way
        //call SetHeroStr(pudge, GetHeroStr(pudge, false)+1, true)  // Dota way
    endif
    
    set pudge = null
endfunction

//===========================================================================
private function Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetKillingUnit(), AID_FLESH_HEAP) > 0
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope




I saw something that is:
JASS:
    private unit array PUI_unit
    private integer array PUI_counter

What does the arraying does?

@Sooda
I don't understand.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Cohadar, please, don't give me nonsense answer.

>>I lol'ed
Do what ever laughing you want and don't spam on my thread.
 

notsoexpert

New Member
Reaction score
4
It basically declares a bunch of the same variable with the same name but a different index in brackets ()
Its useful in loops and stuff like that.

You don't have to remember different names and you can do stuff in loops using arrays, such as:
JASS:
function wth takes nothing returns nothing
local unit u = GetTriggerUnit()
local effect array e 
local integer i = 0
loop
exitwhen i == 10
set e<i>= AddSpecialEffectTarget( &quot; effects//whatevah.mdl&quot;,u,&quot;origin&quot;)
set i = i + 1
endloop
set i = 0
loop
exitwhen i = 10
call DestroyEffect(e<i>)
set e<i> = null
set i = i + 1
endloop
set u = null
endfunction
</i></i></i>

Not very practical or useful here, but its just an example.
 

Joker(Div)

Always Here..
Reaction score
86
@notsoexpert
The post you posted has no relation to what he is asking for.

I'm assuming integer o is going to have 8192 instances of integer i, which seems pointless.
 

notsoexpert

New Member
Reaction score
4
Ah... well... :eek:

I don't see the difference between telling you what a variable array does and what that tiny piece of vJass up there does, because they are extremely similar as to concept and I figured that would be the easiest way to explain it. The "array" part does just that... declares a group of the same-named variable.
And...
I'm assuming integer o is going to have 8192 instances of integer i, which seems pointless.
...how exactly does that answer the question, as well?
 

Trollvottel

never aging title
Reaction score
262
@topic:
where did you find that if not in the documentation?
if i see the context i maybe know what it means.
now i guess its an integer of type O (struct?) with array but the I doesnt really fit in because its declared before and its not in brackets so it doesnt set the max array size o0
 

Sooda

Diversity enchants
Reaction score
318
JASS:

It indeed should syntax, something what would work looks like:
JASS:
struct O
    string s = &quot;Makes sence!&quot;
endstruct

globals
    integer I = 0 // zero
    O array I // This is struct &#039;O&#039; (struct name is O,
              // bad name anyway) array what is named &#039;I&#039;
              // (Again using &#039;I&#039; as a struct name is bad
              // because it dosn&#039; t tell nothing to JASSer.
              // I assume it&#039; s for max performance aka
              // optimised coding.
              // Now both integer and struct array are named
              // same - I. They don&#039; t syntax because &#039;O&#039; is
              // actually integer array.
              //    After vJASS syntax check it could become
              // something like
              // integer array O__I
              // As you can see &#039;O__I&#039; and &#039;I&#039; aren&#039; t same
              // (they never was).
endglobals

That 'integer' before struct O just confuses (it' s syntax error, at least in JASS).
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Ah! Sorry for the confusing... guys.. It is from this post:
JASS:
//===========================================================================
//  Demo spell for using PUI in combination with global arrays
//  to create counters that are attached to unit
//
//  Author: Cohadar
//  Date: 2008.03.08
//===========================================================================

scope FleshHeap

globals
    private constant integer AID_FLESH_HEAP = &#039;A001&#039;
    private constant integer AID_STR_BONUS  = &#039;A002&#039;
    
    private constant integer HERO_PERCENT = 30
    private constant integer UNIT_PERCENT = 3
endglobals

globals    
    // do NOT use this arrays directly, use below functions
    private unit array PUI_unit
    private integer array PUI_counter
endglobals

//===========================================================================
private function GetCount takes unit whichUnit returns integer
    local integer index = GetUnitIndex(whichUnit)
    if PUI_unit[index] != whichUnit then
        set PUI_unit[index] = whichUnit
        set PUI_counter[index] = 0
    endif
    return PUI_counter[index]
endfunction

//===========================================================================
private function AddCount takes unit whichUnit, integer count returns nothing
    local integer index = GetUnitIndex(whichUnit)
    if PUI_unit[index] != whichUnit then
        set PUI_unit[index] = whichUnit
        set PUI_counter[index] = count
    else
        set PUI_counter[index] = PUI_counter[index] + count
    endif
endfunction

//===========================================================================
private function SetCount takes unit whichUnit, integer count returns nothing
    local integer index = GetUnitIndex(whichUnit)
    set PUI_unit[index] = whichUnit
    set PUI_counter[index] = count
endfunction

//===========================================================================
private function Actions takes nothing returns nothing
    local unit pudge = GetKillingUnit()
    local integer level = GetUnitAbilityLevel(pudge, AID_FLESH_HEAP)
    
    if IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) then
        call AddCount(pudge, level*HERO_PERCENT)
    else
        call AddCount(pudge, level*UNIT_PERCENT)
    endif
    
    if GetCount(pudge) &gt;= 100 then
        call SetCount(pudge, 0)
        debug call BJDebugMsg(&quot;|c0000FF00&quot; + &quot;strength increased&quot;)
        call IncUnitAbilityLevel(pudge, AID_STR_BONUS) // green stat way
        //call SetHeroStr(pudge, GetHeroStr(pudge, false)+1, true)  // Dota way
    endif
    
    set pudge = null
endfunction

//===========================================================================
private function Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetKillingUnit(), AID_FLESH_HEAP) &gt; 0
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope

I saw something that is:
JASS:
    private unit array PUI_unit
    private integer array PUI_counter

What does the arraying does?

@Sooda
I don't understand.
 

Cohadar

master of fugue
Reaction score
209
Those are 2 arrays.
One is the array of unit handles,
the other is the array of counters (to be attached to the unit with PUI)

PUI is indexing not attaching system.
Therefore you need arrays to use the pui index.

It is all pretty simple and obvious for anyone who had at least one subject about programming in school.
You simply lack a programming knowledge of arrays that's all.
Not really something I can "answer" you - you need to learn yourself.

Start from the wiki link I posted before.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>It is all pretty simple and obvious for anyone who had at least one subject about programming in school.
Sorry but I don't have any, atleast on my age.

>>You simply lack a programming knowledge of arrays that's all.
Hmm, yea, I agree.

>>Not really something I can "answer" you - you need to learn yourself.
Not to answer me, teach me.

>>Start from the wiki link I posted before.
I don't understand what's written on there... :/

Edit -
AH! GodDamn I am so idiot, it is just a normal array system, I did messed it up with other things.
It is just a <type>array<name>. The example given by sooda it is the same, struct is the "type" and I is the name.
Sorry for the trouble, everyone.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top